OpenCv 3.1 HoughLine (exe stopped working)

asked 2016-03-07 08:17:38 -0600

Hello all,

I'm trying to detect lines in an image using houghLines and Canny edge detector but everytime I get exe has stopped working, and this is really annoying. I'm using the latest pre-compiled exe and visual studio as ide. The canny works perfect but from the moment I try to hough .. problem

Code::

    void detectLines(Mat image) {
    Mat dest = image.clone();
    Mat graydest = image.clone();

    if (image.channels() == 3) {
        cvtColor(image, image, CV_BGR2GRAY);
    }

    double threshold = 5;

    Canny(image, dest, 0.4*threshold, threshold);
    cvtColor(dest, graydest, COLOR_GRAY2BGR);

    imshow("Display Window", dest);
    waitKey(0);

    vector<Vec2f> lines;

    HoughLines(dest, lines,1,CV_PI / 180, 0,0);

    cout << "Number of lines " << lines.size() << endl;

    if (!lines.empty()) {

        for (size_t i = 0; i < lines.size(); i++)
        {
            float rho = lines[i][0];
            float theta = lines[i][1];
            double a = cos(theta), b = sin(theta);
            double x0 = a*rho, y0 = b*rho;

            cout << rho << " " << theta << " " << a << " " << x0 << " " << endl;

            Point pt1(cvRound(x0 + 1000 * (-b)),
                cvRound(y0 + 1000 * (a)));
            Point pt2(cvRound(x0 - 1000 * (-b)),
                cvRound(y0 - 1000 * (a)));

            line(graydest, pt1, pt2, Scalar(0, 0, 255), 3, 8);
        }
    }

    imshow("source", image);
    imshow("Display Window", graydest);
    waitKey(0);

}

Any help would be appreciated :)

Thx in advance

Sklip

edit retag flag offensive close merge delete