2013-06-06 92 views
-3

請看看下面的代碼一個參數值超出範圍

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

這是爲什麼?請幫忙!

+1

如果你確定哪些功能產生錯誤,什麼可能是更有幫助你正在傳遞的輸入參數 – mathematician1975

+2

這不是調試器的用途嗎?或者打印報表並嘗試/捕獲? – Bull

+0

@ user2151446:你能爲QT Creator安裝一個調試器來處理VS 2010編譯器嗎?如果可以,請告訴我 –

回答

3

我得到這個例外,這是

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

+0

是的,就是這樣。謝謝 :) –

0
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()方法自然無法處理的巨大值。