Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

HoughLinesP not able to detect lines

Hi,

I have been struggling with detecting straight lines with HoughLines() after I used the canny edge detector. The canny edge detector works fine I believe (rectangle with triangle). But from the houghtransform I'm not been able to detect those lines. Underneath the pictures you will find the code I have been using and tried to play with the thershold values etc. I'm not really sure on how to improve the houghlines. Anyone who can help me?

Thanks

image descriptionimage description

    Mat img = this->frame.clone();
    cv::cvtColor(img,img,CV_BGR2GRAY);

    cv::Size size(3,3);
    cv::GaussianBlur(img,img,size,0);

    adaptiveThreshold(img, img,255,CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY,249,10);
    cv::imwrite("threshold.jpg", img);

    cv::bitwise_not(img, img);
    cv::imwrite("bitwise.jpg", img);
    int lowThreshold = 100;
    cv::Canny( img, img, lowThreshold, lowThreshold*3, 3 );
    cv::imwrite("canny.jpg", img);

    vector<Vec4i> lines;
    HoughLinesP(img, lines, 1, CV_PI/180, 40, 5, 50);
    cout << lines.size() << endl;
    for( size_t i = 0; i < lines.size(); i++ )
    {
        line( this->frame, Point(lines[i][0], lines[i][1]),
            Point(lines[i][2], lines[i][3]), Scalar(0,0,255), 2, 8 );
    }
    cv::imwrite("hough.jpg", frame);
    cv::imshow("frame", this->frame);
    cv::waitKey(1);

HoughLinesP not able to detect lines

Hi,

I have been struggling with detecting straight lines with HoughLines() after I used the canny edge detector. The canny edge detector works fine I believe (rectangle with triangle). But from the houghtransform I'm not been able to detect those lines. Underneath the pictures you will find the code I have been using and tried to play with the thershold values etc. I'm not really sure on how to improve the houghlines. Anyone who can help me?

Thanks

image descriptionimage description

    Mat img = this->frame.clone();
    cv::cvtColor(img,img,CV_BGR2GRAY);

    cv::Size size(3,3);
    cv::GaussianBlur(img,img,size,0);

    adaptiveThreshold(img, img,255,CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY,249,10);
    cv::imwrite("threshold.jpg", img);

    cv::bitwise_not(img, img);
    cv::imwrite("bitwise.jpg", img);
    int lowThreshold = 100;
    cv::Canny( img, img, lowThreshold, lowThreshold*3, 3 );
    cv::imwrite("canny.jpg", img);

    vector<Vec4i> lines;
    HoughLinesP(img, lines, 1, CV_PI/180, 40, 5, 50);
    cout << lines.size() << endl;
    for( size_t i = 0; i < lines.size(); i++ )
    {
        line( this->frame, Point(lines[i][0], lines[i][1]),
            Point(lines[i][2], lines[i][3]), Scalar(0,0,255), 2, 8 );
    }
    cv::imwrite("hough.jpg", frame);
    cv::imshow("frame", this->frame);
    cv::waitKey(1);

EDIT I don't have the original image anymore, but I still have the image after the gaussian filter image description

HoughLinesP not able to detect lines

Hi,

I have been struggling with detecting straight lines with HoughLines() after I used the canny edge detector. The canny edge detector works fine I believe (rectangle with triangle). But from the houghtransform I'm not been able to detect those lines. Underneath the pictures you will find the code I have been using and tried to play with the thershold values etc. I'm not really sure on how to improve the houghlines. Anyone who can help me?

Thanks

image descriptionimage description

    Mat img = this->frame.clone();
    cv::cvtColor(img,img,CV_BGR2GRAY);

    cv::Size size(3,3);
    cv::GaussianBlur(img,img,size,0);

    adaptiveThreshold(img, img,255,CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY,249,10);
    cv::imwrite("threshold.jpg", img);

    cv::bitwise_not(img, img);
    cv::imwrite("bitwise.jpg", img);
    int lowThreshold = 100;
    cv::Canny( img, img, lowThreshold, lowThreshold*3, 3 );
    cv::imwrite("canny.jpg", img);

    vector<Vec4i> lines;
    HoughLinesP(img, lines, 1, CV_PI/180, 40, 5, 50);
    cout << lines.size() << endl;
    for( size_t i = 0; i < lines.size(); i++ )
    {
        line( this->frame, Point(lines[i][0], lines[i][1]),
            Point(lines[i][2], lines[i][3]), Scalar(0,0,255), 2, 8 );
    }
    cv::imwrite("hough.jpg", frame);
    cv::imshow("frame", this->frame);
    cv::waitKey(1);

EDIT I don't have the original image anymore, but I still have the image after the gaussian filter image description