我正在尝试使用 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”。有什么建议。?
2 回答
达令说
TA贡献1821条经验 获得超6个赞
试试这个,看看它是如何工作的:
while(True):
f1 = img[0]
f2 = img[1]
fg1 = fgbg.apply(f1)
fb2 = fgbg.apply(f2)
cv2.imshow('original', frame)
cv2.imshow('fg1', fg1)
cv2.imshow('fg2', fb2)
# cv2.imshow('fg', cv2.bitwise_and(frame, frame, mask=fgmask))
time.sleep(1 / fps)
if(cv2.waitKey(1) & 0xFF == ord('q')) : break
cv2.destroyAllWindows()
添加回答
举报
0/150
提交
取消