2012-11-05 91 views
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 newLinestd::vector<float> newLine(4)和它的作品。爲什麼?

回答

0

這些斷言只是在那裏檢查您的數據的維度是正確的(例如,一組二維或三維點)。所以如果他們被提出,你可能沒有正確地初始化你的數據,但是我不能說沒有代碼

+0

增加了代碼。 'temp2'總是大於2. – krzych

+1

將'Vec4f newLine更改爲'std :: vector newLine [4],並且一切正常。爲什麼? – krzych

+0

它不適用於newLine作爲Vec4f,但與newLine一起使用作爲矢量?不知道爲什麼。 fitLine需要一個OutputArray參數,不知道兼容性btw OutputArray,VecXf和向量 remi