gpt4 book ai didi

c++ - 为什么函数 calcOpticalFlowPyrLK 返回相同的值?

转载 作者:行者123 更新时间:2023-11-28 07:38:50 26 4
gpt4 key购买 nike

我正在做一个 opencv 应用程序,我正在使用 de LucasKanada 算法。我使用这个功能:

calcOpticalFlowPyrLK(pregray, gray,points[0], points[1], status, err, Size(31,31),3, termcrit, 0, 0.001);

计算点的新位置,但例如点 [1][2] 与点 [0][2] 具有相同的值,不会改变。为什么?

最佳答案

如果不了解如何初始化函数的参数,就很难回答您的问题。但我的猜测是您的 prevgray 图像与 gray 相同。

Mat 对象的复制运算符(即 =)只会复制标题和指向矩阵的指针,而不是数据本身。如果您从相机抓取图像,请确保复制图像数据。像这样:

VideoCapture cap;
cap.open(0);
Mat frame, gray, prevgray;

for(;;)
{
cap >> frame;
gray = rgb2gray(frame);

calcOpticalFlowPyrLK(pregray, gray,points[0], points[1], status, err,
Size(31,31),3, termcrit, 0, 0.001);

gray.copyTo(prevGray); // make sure you copy the data

// if you do
// prevgray = gray;
// then in the next iteration gray and prevgray will point to the same data
}

关于c++ - 为什么函数 calcOpticalFlowPyrLK 返回相同的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16241700/

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