I’m using OpenCV fitLine() function.
Sometimes following exception are thrown:
..\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
Also some assertions are failed:
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
Has someone similiar issues? Maybe points are too bad for fitting line? Should I change fitLine() function parameters?
Code
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();
}
I’ve changed Vec4f newLine to std::vector<float> newLine(4) and it works. Why?
those assertion are just there to check the dimensions of your data are correct (eg, set of 2D or 3D points). So if they are raised, you have probably not correctly initialised your data, but I cannot tell without the code