1
我正在使用OpenCV fitLine()
函數。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
有人曾經similiar問題?擬合線可能點太差了?我應該更改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)
和它的作品。爲什麼?
增加了代碼。 'temp2'總是大於2. – krzych
將'Vec4f newLine更改爲'std :: vector newLine [4],並且一切正常。爲什麼? –
krzych
它不適用於newLine作爲Vec4f,但與newLine一起使用作爲矢量?不知道爲什麼。 fitLine需要一個OutputArray參數,不知道兼容性btw OutputArray,VecXf和向量 –
remi