Ask Your Question

# Revision history [back]

### Draw difference in countours using reference images

Hi, I am trying to draw contours from the difference which I have got by comparing 2 reference images but somehow I am not able to draw that difference using draw contours Any suggestion will be very helpful

Code:

import cv2
import numpy as np
import imutils

f = cv2.imread("2.jpg")
s = cv2.imread("1.jpg")

difference = cv2.absdiff(s, f)

grey = cv2.cvtColor(difference,cv2.COLOR_BGR2GRAY)
c,h = cv2.findContours(grey, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)

for contour in c:
area = cv2.contourArea(contour)

if area > 10:
print(area)
c = cv2.drawContours(difference, contour, -1, (0, 255, 0), 3)
cv2.imwrite("Frame.jpg", c)
#cv2.imshow("difference", difference)
cv2.waitKey(1)
cv2.destroyAllWindows()


using below reference image

1st image

2nd image