gpt4 book ai didi

c++ - OpenCV 拟合线异常

转载 作者:太空宇宙 更新时间:2023-11-04 14:13:03 25 4
gpt4 key购买 nike

我正在使用 OpenCV fitLine()功能。

有时会抛出以下异常:

..\opencv\modules\core\src\matrix.cpp:1219: error: (-215) 
dims == 2 && ((size[0] == sz.height && size[1] == sz.width) || (allocateVector
&& size[0] == sz.width && size[1] == sz.height)) in function create

还有一些断言失败了:

OpenCV Error: Assertion failed (dims == 2 && ((size[0] == sz.height &&
size[1] == sz.width) || (allocateVector && size[0] == sz.width &&
size[1] == sz.height))) in create

有人有类似的问题吗?也许点对拟合线来说太糟糕了?我应该更改 fitLine()函数参数?

代码

cv::Vec4f newLine;
if(temp.size() >= 2)
{
qDebug()<<"Correcting line";
std::vector<cv::Point2f> temp2;
for(std::vector<std::pair<cv::Point2f,float> >::iterator i = temp.begin();
i != temp.end(); i++)
{
temp2.push_back((*i).first);
}
qDebug()<<"temp2 size: "<<temp2.size();
try{
cv::fitLine(temp2,newLine,CV_DIST_HUBER,0,0.01,0.01);
}
catch(cv::Exception e)
{
qDebug()<<e.what();
}

我已经改变了Vec4f newLinestd::vector<float> newLine(4)它有效。为什么?

最佳答案

这些断言只是为了检查数据的维度是否正确(例如,一组 2D 或 3D 点)。因此,如果它们被引发,您可能没有正确初始化您的数据,但没有代码我无法判断

关于c++ - OpenCV 拟合线异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13231785/

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