我正在使用 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 newLine
至 std::vector<float> newLine(4)
它有效。为什么?
最佳答案
这些断言只是为了检查数据的维度是否正确(例如,一组 2D 或 3D 点)。因此,如果它们被引发,您可能没有正确初始化您的数据,但没有代码我无法判断
关于c++ - OpenCV 拟合线异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13231785/