c++ - OpenCV 拟合线异常

标签 c++ opencv

我正在使用 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 newLinestd::vector<float> newLine(4)它有效。为什么?

最佳答案

这些断言只是为了检查数据的维度是否正确(例如,一组 2D 或 3D 点)。因此,如果它们被引发,您可能没有正确初始化您的数据,但没有代码我无法判断

关于c++ - OpenCV 拟合线异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13231785/

相关文章:

c++ - win32 c++ 在没有子类化的编辑控件中检测到 'enter'?

c++ - constexpr 静态成员与变量

android - 在android上使用Qt蓝牙连接到arduino

c++ - 使用 OpenCV 的低质量空中拼接

opencv - 从图像中删除框/矩形

c++ - 将 cv::Mat 转换为 vector<int>

c++ - 将显示设置更改为重复的 WinAPI 函数

c++ - 通过 MPI 发送和接收 2D 数组

python - OCR的清洁图像

c++ - 将 point2d 转换为 Mat