2

我正在尝试使用 python 绑定在 OpenCV 2.3.1 中制作 LK 跟踪器。当我做

calcOpticalFlowPyrLK(img1, img2,
                   template_pt, target_pt, status, err, 
                   (win_size_lk, win_size_lk), 0, TERM_CRITERIA_EPS, 
                   (TERM_CRITERIA_EPS | TERM_CRITERIA_COUNT, 10, 0.03), eig)

我越来越

TypeError:不是一个numpy数组

在哪里

img1, img2 - iplimage
template_pt, target_pt - A List consisting of tuples with two integers eg. [(120,140),(300,400),..]
win_size_lk = 10
eig = 0.001
status = ""
err = None

此处提供有关 cv2.calcOpticalFlowPyrLK() 的更多信息

http://opencv.itseez.com/modules/video/doc/motion_analysis_and_object_tracking.html?highlight=opticalflow#cv.CalcOpticalFlowPyrLK

当我设置

eig = np.array([(0.0,1.0),(1.0,0.0)])

它给了我以下错误

TypeError:只有长度为 1 的数组可以转换为 Python 标量

这里可能是什么问题?

4

1 回答 1

1

我已经弄清楚了问题所在。

img1, img2 should be numpy array
template_pt, target_pt should be numpy array

所以,

target_pt, status, track_error = calcOpticalFlowPyrLK(img1, 
                  img2, 
                  template_pt, 
                  target_pt, 
                  winSize=(win_size_lk, win_size_lk), 
                  flags = OPTFLOW_USE_INITIAL_FLOW,
                  criteria = (TERM_CRITERIA_EPS | TERM_CRITERIA_COUNT, 10, 0.03))

效果很好。

于 2012-06-03T08:48:46.033 回答