Строки Hough преобразуют перерывы в программе opencv

Я пытаюсь использовать преобразование houghlines. Функция работает хорошо, но программа прерывается после imshow("обнаруженные строки",cdst) где-то в файле free.c в функции free_base.

пожалуйста, помогите мне

Вот мой код:

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

person user2327226    schedule 27.04.2013    source источник


Ответы (1)


Кажется, что ваша функция «int houghline (String filename)» не имеет оператора возврата.

Пожалуйста, добавьте "возврат 0;" в конце функции и посмотрите, работает ли она.

person user2821584    schedule 01.10.2013