编辑..在早些时候在我家后面测试不同的图像,我在背景中得到一些噪音,我怎么能消除这种噪音所以我只是捡起我的狗?
#Import Images
Background_Image = cv2.imread('bck.jpg',0)
Forground_Image = cv2.imread('dog.jpg',0)
#
diff = cv2.absdiff(Background_Image,Forground_Image)
thresh = cv2.threshold(diff, 80, 255, cv2.THRESH_BINARY)[1]
thresh = cv2.dilate(thresh, None, iterations=2)
(_, cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for c in cnts:
(x, y, w, h) = cv2.boundingRect(c)
cv2.rectangle(Forground_Image, (x, y), (x + w, y + h), (0, 255, 0), 4)
cv2.imshow('Test',Background_Image)
cv2.imshow('Test1',Forground_Image)
cv2.waitKey()
答案 0 :(得分:1)
OpenCV已经有一些背景减法实现,我认为你会比使用一些手动解决方案更好。 教程:http://docs.opencv.org/trunk/db/d5c/tutorial_py_bg_subtraction.html
生成差异图像,然后: