【问题标题】:One of arguments' values is out of range [closed]参数之一的值超出范围[关闭]
【发布时间】:2013-06-06 06:50:38
【问题描述】:

请看下面的代码

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <vector>

using namespace cv;
using namespace std;

void houghTransform(int,void*);
Mat image,lines,dst,cdst;
int thresh;
const char* imageWindow = "Image Window";

int main()
{
    image = imread("DSC01894.jpg");

    //Turning the dst image into greyscale


    if(image.data!=0)
    {
        cv::Canny(image,dst,50,200,3);
        cv::cvtColor(dst,cdst,CV_GRAY2BGR);

        cv::createTrackbar("Threshold",imageWindow,&thresh,255,houghTransform);
        houghTransform(0,0);
    }
    else
    {
        cout << "Image cannot be read" << endl;
    }

    namedWindow("Image");
    imshow("Image",image);

    waitKey(0);

}

void houghTransform(int, void *)
{
    vector<Vec4i>lines;

    cv::HoughLinesP(dst,lines,1,CV_PI/180,thresh,50,10);

    for(size_t i=0;i<lines.size();i++)
    {
        Vec4i l = lines[i];

        cv::line(cdst,Point(l[0],l[1]),Point(l[2],l[3]),Scalar(0,0,255),3,CV_AA);
    }

    imshow(imageWindow,cdst);
}

当它运行时,我得到一个运行时错误,

One of arguments' values is out of range。它应该在

cv::HoughLinesP(dst,lines,1,CV_PI/180,thresh,50,10);

cv::line(cdst,Point(l[0],l[1]),Point(l[2],l[3]),Scalar(0,0,255),3,CV_AA);

这是为什么?

【问题讨论】:

  • 如果您确定哪个函数产生错误以及您传递的输入参数可能会更有帮助
  • 这不是调试器的用途吗?或者打印语句并尝试/捕获?
  • @user2151446:您可以为使用 VS 2010 编译器的 QT Creator 安装调试器吗?如果可以,请告诉我
  • 你能通过 std::cout 检查值吗

标签: c++ image opencv image-processing artificial-intelligence


【解决方案1】:

我得到了这个异常,即

OpenCV Error: One of arguments' values is out of range (rho, theta and threshold
 must be positive) in unknown function, file C:\slave\builds\WinInstallerMegaPac
 k\src\opencv\modules\imgproc\src\hough.cpp, line 718

在这段代码中

    if( rho <= 0 || theta <= 0 || threshold <= 0 )
        CV_Error( CV_StsOutOfRange, "rho, theta and threshold must be positive" );

cvHoughLines2() 中,由 cv::HoughLinesP() 调用。

传递给HoughLinesP()的参数是:

rho=1
theta=0.0174533
threshold=0

有问题:阈值不允许为0。

【讨论】:

    【解决方案2】:
    Vec4i l = lines[i];
    

    这里,l 可能只有一个元素

    或在:

    cv::line(cdst,Point(l[0],l[1]),Point(l[2],l[3]),Scalar(0,0,255),3,CV_AA);
    

    线的端点可以指示图像的边界之外。您可以检查Point(l[0],l[1])Point(l[2],l[3]) 如果l 的元素少于4 个,那么其他剩余点只是垃圾并且可能有一些line() 方法无法自然处理的巨大值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-05
      • 2017-05-15
      • 2014-01-25
      • 2018-07-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多