我正在尝试使用 OpenCV 的 BackgroundSubtractorMOG2 方法突出显示两个几乎相似的图像蒙版之间的差异。
我的代码:
def Approach_2():
img = [0, 0]
img[0] = cv2.imread('images/4-left.PNG', cv2.IMREAD_GRAYSCALE)
img[1] = cv2.imread('images/4-right.PNG', cv2.IMREAD_GRAYSCALE)
img[0], img[1] = make_similar(img[0], img[1]) # make two images similar (equal width and height) by applying scaling, translation and performs Canny edge detection on two images
fps = 5
fgbg = cv2.createBackgroundSubtractorMOG2(detectShadows=True)
cv2.imshow("A", img[0])
cv2.imshow("B", img[1])
i = 1
while(True):
frame = img[i]
i = 1-i
fgmask = fgbg.apply(frame)
cv2.imshow('original', frame)
cv2.imshow('fg', fgmask)
# cv2.imshow('fg', cv2.bitwise_and(frame, frame, mask=fgmask))
time.sleep(1 / fps)
if(cv2.waitKey(1) & 0xFF == ord('q')) : break
cv2.destroyAllWindows()
if __name__ == '__main__':
Approach_2()
但我只得到空白的“fgmask”。
有什么建议。?
DIEA
达令说
相关分类