gpt4 book ai didi

python - 类型错误 : is not a numpy array in cv2. calcOpticalFlowPyrLK()

转载 作者:太空宇宙 更新时间:2023-11-03 21:48:06 24 4
gpt4 key购买 nike

我正在尝试使用 Python 绑定(bind)在 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)

我得到了

类型错误:不是一个 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)])

它给了我以下错误

类型错误:只有长度为 1 的数组可以转换为 Python 标量

这可能是什么问题?

最佳答案

我已经找到问题了。

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))

效果很好。

关于python - 类型错误 : <unknown> is not a numpy array in cv2. calcOpticalFlowPyrLK(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10852866/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com