1 | initial version |
Hi Ranganath try the following code:
import cv2 im = cv2.imread("image.jpg", 0) im1 = cv2.imread("image1.jpg", 0)
diff = cv2.absdiff(im, im1) ret, thresh = cv2.threshold(diff, 0, 255, cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU) contours, hierarchy = cv2.findContours(thresh, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) mask = cv2.cvtColor(im1, cv2.COLOR_GRAY2BGR)
try: hierarchy = hierarchy[0] except: hierarchy = []
for contour in contours[:-1]: (x, y, w, h) = cv2.boundingRect(contour) area = cv2.contourArea(contour) if area>100: cv2.rectangle(im1, (x, y), (x+w, y+h), (255, 0, 0), 3)
cv2.imshow("mask", im1) cv2.imshow("thresh", thresh) cv2.waitKey(0)
2 | No.2 Revision |
Hi Ranganath try the following code:
import cv2
im = cv2.imread("image.jpg", 0)
im1 = cv2.imread("image1.jpg",