我正在尝试使用 cv2.calcOpticalFlowPyrLK 在 Python 上实现 Lucas-Kanade 光流算法。但是,当我尝试画一条线来连接当前点和以前的点以及点本身时,函数返回 None。
这是代码
#draw the overlaying tracking img
for i,(new,old) in enumerate(zip(good_new,good_old)):
a,b = new.ravel() #tmp new value
c,d = old.ravel() #tmp old value
#draws a line connecting the old point with the new point
mask = cv2.line(mask,(a,b),(c,d),color[i].tolist(),2) #returns None... why??
#draws the new point
frame = cv2.circle(frame,(a,b),5,color[i].tolist(),-1) #returns None... why??
img = cv2.add(frame,mask)
#show on window
cv2.imshow("frame",img)
a,b,c,d 是 numpy.float32
frame 是我从网络摄像头读取的值
掩码初始化为一个零数组
颜色是一个随机数组
这是我尝试 imshow 时收到的错误消息
error: /Users/vagrant/pisi-64bit/tmp/opencv-2.4.5-2/work/opencv-2.4.5/modules/core/src/array.cpp:2482: error: (-206) Unrecognized or unsupported array type in function cvGetMat
我真的很感激帮助!