我正在使用 OpenCVfitLine()
功能。
有时会抛出以下异常:
..\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)
并且有效。为什么?