2013-04-27 1 views
0

나는 houghlines 변환을 사용하려고합니다. 이 함수는 정상적으로 작동하지만 free_base 함수의 free.c 파일 어딘가에있는 imshow ("detected lines", cdst) 이후 프로그램이 중단됩니다.hough 회선 tansform opencv 프로그램이 끊깁니다.

#include<opencv\cv.h> 
#include<opencv/cxcore.h> 
#include<opencv/highgui.h> 
#include<opencv2\imgproc\imgproc.hpp> 
#include<iostream> 
#include<vector> 
#include<math.h> 
#include <string> 

using namespace cv; 
using namespace std; 

void help() 
{ 
cout << "\nThis program demonstrates line finding with the Hough transform.\n" 
     "Usage:\n" 
     "./houghlines <image_name>, Default is pic1.jpg\n" << endl; 
} 

int houghline(String filename) 
{ 



//const char* filename = argc >= 2 ? argv[1] : "Release\\D.bmp.bmp"; 


Mat src = imread(filename, 0); 
if(src.empty()) 
{ 
    help(); 
    cout << "can not open " << filename << endl; 
    return -1; 
} 

Mat dst, cdst; 
Canny(src, dst, 50, 200, 3); 
cvtColor(dst, cdst, CV_GRAY2BGR); 

/* 
vector<Vec2f> lines; 
    HoughLines(dst, lines, 1, CV_PI/180, 100, 0, 0); 
    float aaa=lines[1][0]; 

    for(size_t i = 0; i < lines.size(); i++) 
    { 
    float rho = lines[i][0], theta = lines[i][1]; 
    Point pt1, pt2; 
    double a = cos(theta), b = sin(theta); 
    double x0 = a*rho, y0 = b*rho; 
    pt1.x = cvRound(x0 + 1000*(-b)); 
    pt1.y = cvRound(y0 + 1000*(a)); 
    pt2.x = cvRound(x0 - 1000*(-b)); 
    pt2.y = cvRound(y0 - 1000*(a)); 
    line(cdst, pt1, pt2, Scalar(0,0,255), 3, CV_AA); 
    } 

*/ 



vector<Vec4i> lines; 
    HoughLinesP(dst, lines, 1, CV_PI/180, 10, 25, 2); 
    /* 
with the arguments: 

    dst: Output of the edge detector. It should be a grayscale image (although in fact it is a binary one) 
    lines: A vector that will store the parameters (x_{start}, y_{start}, x_{end}, y_{end}) of the detected lines 
    rho : The resolution of the parameter r in pixels. We use 1 pixel. 
    theta: The resolution of the parameter \theta in radians. We use 1 degree (CV_PI/180) 
    threshold: The minimum number of intersections to “detect” a line 
    minLinLength: The minimum number of points that can form a line. Lines with less than this number of points are disregarded. 
    maxLineGap: The maximum gap between two points to be considered in the same line 
*/ 

    for(size_t i = 0; i < lines.size(); i++) 
    { 
    Vec4i l = lines[i]; 
    line(cdst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(255,0,0), 1, CV_AA); 
    imshow("detected lines", cdst); 
    waitKey(); 
    } 

imshow("source", src); 
imshow("detected lines", cdst); 

} 

int main(int argc, char** argv) 
{ 
    //for(char alpha='A';alpha<='Z';alpha++) 
     //String filename="C:\\Users\\Abhinav\\Documents\\Visual Studio 2012\\Projects\\Classes\\Release\\Microsoft Sans Serif\\"+to_string(alpha)+".bmp"; 
    try{houghline("C:\\Users\\Abhinav\\Documents\\Visual Studio 2012\\Projects\\Classes\\Release\\Microsoft Sans Serif\\A.bmp");} 
    //houghline("C:\\Users\\Abhinav\\Documents\\Visual Studio 2012\\Projects\\Classes\\Release\\Microsoft Sans Serif\\B.bmp"); 
    catch(Exception e){cout<<e.err;} 
waitKey(); 


return 0; 
} 

답변

0

당신의 기능 "INT의 houghline (문자열 파일 이름)"에는 return 문이없는 것 같습니다 :

여기

내 코드가 저를 도와주십시오.

"return 0;"을 추가하십시오. 함수가 끝나고 작동하는지 확인하십시오.