@@ -27,23 +27,22 @@ void IPLHoughLines::init()
2727
2828 // basic settings
2929 setClassName (" IPLHoughLines" );
30- setTitle (" Circle Hough Transform " );
30+ setTitle (" Hough Lines " );
3131 setCategory (IPLProcess::CATEGORY_OBJECTS);
3232 setOpenCVSupport (IPLOpenCVSupport::OPENCV_ONLY);
33- setDescription (" The circle Hough Transform (CHT) is a feature extraction technique for detecting circles ." );
33+ setDescription (" Finds lines in a binary image using the standard Hough transform ." );
3434
3535 // inputs and outputs
3636 addInput (" Image" , IPLData::IMAGE_COLOR);
3737 addOutput (" Hough Result" , IPLImage::IMAGE_GRAYSCALE);
38- addOutput (" Circle Overlay" , IPLImage::IMAGE_COLOR);
39- addOutput (" Circle Positions" , IPLImage::POINT);
38+ addOutput (" Line Overlay" , IPLImage::IMAGE_COLOR);
4039
4140 // properties
42- addProcessPropertyInt ( " thresholdCanny " , " Threshold 1 " , " Upper threshold for the internal Canny edge detector " , 200 , IPL_WIDGET_SLIDER, 1 , 200 );
43- addProcessPropertyInt ( " thresholdCenter " , " Threshold 2 " , " Threshold for center detection " , 100 , IPL_WIDGET_SLIDER, 1 , 200 );
44- addProcessPropertyInt (" minRadius " , " Min. Radius " , " " , 1 , IPL_WIDGET_SLIDER, 1 , 1000 );
45- addProcessPropertyInt (" maxRadius " , " Max. Radius " , " " , 5 , IPL_WIDGET_SLIDER, 1 , 1000 );
46- addProcessPropertyInt (" minDist " , " Min. Distance " , " " , 100 , IPL_WIDGET_SLIDER, 1 , 1000 );
41+ addProcessPropertyDouble ( " rho " , " Rho " , " Distance resolution of the accumulator in pixels " , 1 , IPL_WIDGET_SLIDER, 0 , 10 );
42+ addProcessPropertyDouble ( " theta " , " Min. Radius " , " Angle resolution of the accumulator in radians. " , 0.01 , IPL_WIDGET_SLIDER, 0 , 5.14 );
43+ addProcessPropertyInt (" threshold " , " Threshold " , " Accumulator threshold parameter. " , 0 , IPL_WIDGET_SLIDER, 1 , 1000 );
44+ addProcessPropertyInt (" minLenght " , " Min. Length " , " " , 1 , IPL_WIDGET_SLIDER, 1 , 1000 );
45+ addProcessPropertyInt (" maxLineGap " , " Max. Line Gap " , " " , 1 , IPL_WIDGET_SLIDER, 1 , 1000 );
4746}
4847
4948void IPLHoughLines::destroy ()
@@ -59,11 +58,11 @@ bool IPLHoughLines::processInputData(IPLImage* image , int, bool useOpenCV)
5958 _overlay = NULL ;
6059
6160 // get properties
62- int thresholdCanny = getProcessPropertyInt ( " thresholdCanny " );
63- int thresholdCenter = getProcessPropertyInt ( " thresholdCenter " );
64- int minRadius = getProcessPropertyInt (" minRadius " );
65- int maxRadius = getProcessPropertyInt (" maxRadius " );
66- int minDist = getProcessPropertyInt (" minDist " );
61+ double rho = getProcessPropertyDouble ( " rho " );
62+ double theta = getProcessPropertyDouble ( " theta " );
63+ int threshold = getProcessPropertyInt (" threshold " );
64+ int minLength = getProcessPropertyInt (" minLenght " );
65+ int maxLineGap = getProcessPropertyInt (" maxLineGap " );
6766
6867 notifyProgressEventHandler (-1 );
6968 cv::Mat input;
@@ -72,28 +71,21 @@ bool IPLHoughLines::processInputData(IPLImage* image , int, bool useOpenCV)
7271 result = cv::Scalar (0 );
7372 cvtColor (image->toCvMat (), input, CV_BGR2GRAY);
7473
75- std::vector<cv::Vec3f> circles;
76- cv::HoughCircles (input, circles, CV_HOUGH_GRADIENT, 2 , input.rows /4 , thresholdCanny, thresholdCenter, minRadius, maxRadius);
77-
78- // WARNING: cv::HoughCircles does not work in debug mode!!!
79- // destroys the std::vector<cv::Vec3f> circles;
74+ std::vector<cv::Vec4i> lines;
75+ cv::HoughLinesP (input, lines, rho, theta, threshold, minLength, maxLineGap);
8076
8177 std::stringstream s;
82- s << " Circles found: " ;
83- s << circles .size ();
78+ s << " Lines found: " ;
79+ s << lines .size ();
8480 addInformation (s.str ());
8581
86- for (int i = 0 ; i < circles .size (); i++ )
82+ for (int i = 0 ; i < lines .size (); i++ )
8783 {
88- cv::Point center (round (circles[i][0 ]), round (circles[i][1 ]));
89- int radius = cvRound (circles[i][2 ]);
90- // circle center
91- cv::circle (overlay, center, 3 , cv::Scalar (0 ,255 ,0 ), -1 , 8 , 0 );
92- // circle outline
93- cv::circle (overlay, center, radius, cv::Scalar (0 ,0 ,255 ), 3 , 1 , 0 );
84+ cv::Vec4i l = lines[i];
85+ cv::line (overlay, cv::Point (l[0 ], l[1 ]), cv::Point (l[2 ], l[3 ]), cv::Scalar (0 ,0 ,255 ), 3 , CV_AA);
9486
9587 // raw result
96- cv::circle (result, center, radius , cv::Scalar (255 ), - 1 );
88+ cv::line (result, cv::Point (l[ 0 ], l[ 1 ]) , cv::Point (l[ 2 ], l[ 3 ]), cv:: Scalar (255 ), 1 , CV_AA );
9789 }
9890
9991 _overlay = new IPLImage (overlay);
@@ -106,15 +98,12 @@ bool IPLHoughLines::processInputData(IPLImage* image , int, bool useOpenCV)
10698 * \brief IPLHoughLines::getResultData
10799 * index == 0: "Hough Result", IPLImage::IMAGE_GRAYSCALE
108100 * index == 1: "Circle Overlay", IPLImage::IMAGE_COLOR
109- * index == 2: "Circle Positions", IPLImage::IMAGE_POINT
110101 * \return
111102 */
112103IPLData* IPLHoughLines::getResultData (int index)
113104{
114105 if (index == 0 )
115106 return _result;
116- else if (index == 1 )
117- return _overlay;
118107 else
119- return _result ;
108+ return _overlay ;
120109}
0 commit comments