其中一个参数的值超出了范围

请查看以下代码

#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");    //将dst图像转换为灰度图    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 << "无法读取图像" << 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);}

运行时,我遇到了运行时错误,

其中一个参数的值超出了范围。应该是在

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);

为什么会这样?


回答:

我遇到了这个异常,内容是

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=1theta=0.0174533threshold=0

问题在于:阈值(threshold)不允许为0。

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注