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


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:
        c = cv2.drawContours(difference, contour, -1, (0, 255, 0), 3) 
cv2.imwrite("Frame.jpg", c)
#cv2.imshow("difference", difference)

using below reference image

1st image

image description

2nd image

image description