1
我在python中使用cv2.calcOpticalFlowFarneback()
來獲得光流的結果,但在嘗試使用它的結果時出現問題。我想繪製該函數返回的更改,但在Python中循環太慢。我相信有一種方法可以讓它更快。這是我嘗試OpenCV中沒有循環的calcOpticalFlowFarneback的繪製結果
flow = cv2.calcOpticalFlowFarneback(prev_gray, gray, pyr_scale=0.5, levels=5, winsize=13, iterations=10, poly_n=5, poly_sigma=1.1, flags=0,flow=None)
for y in range(0, flow.shape[0], 5):
for x in range(0, flow.shape[1], 5):
fx, fy = flow[y, x]
cv2.line(frame2, (x,y), (int(x+fx),int(y+fy)), (255,0,0))
cv2.circle(frame2, (x,y), 1, (255,0,0), -1)