我做了一个小测试cv2.calcOpticalFlowFarneback()
来检查它的结果有多稳定。在我的测试中,我用相机拍了一张快照,剪切了两个重叠的图像,(0,10)
它们之间有距离。我对每个像素都是预期(0,10)
的,但结果却大不相同。
import cv2
cap = cv2.VideoCapture(0)
ret, img = cap.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.imshow('gray', gray)
left = gray[:-5, :]
right = gray[5:, :]
flow = cv2.calcOpticalFlowFarneback(left, right, 0.5, 3, 15, 3, 5, 1.2, 0)
flowx = flow[:,:,0]
flowy = flow[:,:,1]
cv2.imshow('flowx', flowx)
cv2.imshow('flowy', flowy)
print 'x.mean:', flowx.mean()
print 'x.max:', flowx.max()
print 'x.min:', flowx.min()
print 'y.mean:', flowy.mean()
print 'y.max:', flowy.max()
print 'y.min:', flowy.min()
cv2.waitKey()
结果:
x.mean: -0.00440598979749
x.max: 1.53141
x.min: -1.95973
y.mean: -2.53464987664
y.max: 0.844686
y.min: -5.43879
我怎样才能使它更接近我的预期(0,10)
结果?