Tag Archives: cvhoughlines2 opencv

OpenCV – cvHoughLines2 example on QT

#include <QtCore/QCoreApplication>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv/cv.h>


IplImage *image, *image1, *image2;


int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);



    image  = cvLoadImage("C:\\Temp\\99.jpg");

    IplImage* image1 = cvCreateImage( cvGetSize(image), 8, 1 );

    IplImage* image2 = cvCreateImage( cvGetSize(image), 8, 3 );

    CvMemStorage* storage = cvCreateMemStorage(0);

    CvSeq* lines = 0;


    cvCanny( image, image1, 50, 200, 3 );

    cvCvtColor( image1, image2, CV_GRAY2BGR );


    lines = cvHoughLines2( image1, storage, CV_HOUGH_PROBABILISTIC, 1, CV_PI/180, 50, 50, 10 );

    for( int i = 0; i < lines->total; i++ )
    {
        CvPoint* line = (CvPoint*)cvGetSeqElem(lines,i);
        cvLine( image2, line[0], line[1], CV_RGB(255,0,0), 3, 8 );
    }




    cvShowImage( "Original", image );
    cvShowImage( "cvHoughLines2", image2 );


    return a.exec();

}


 

3

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS