# Include "opencv2/highgui. HPP "# include" opencv2/imgproc. HPP "# include <iostream> using namespace CV; using namespace STD; static void help () {cout <" \ nthis program demonstrates Line Finding with the Hough transform. \ n "" Usage: \ n "". /houghlines <image_name>, default is pic1.png \ n "<Endl;} int main (INT argc, char ** argv) {const char * filename = argc> = 2? Argv [1]: "pic1.png"; MAT src = imread (filename, 0); If (SRC. empty () {help (); cout <"can not open" <FILENAME <Endl; Return-1;} mat DST, cdst; Kan (SRC, DST, 50,200, 3); cvtcolor (DST, cdst, cv_gray2bgr); # If 0 vector <vec2f> lines; // DST: the output image of the Canny edge detection; line: used to store the vector of the parameter; // 1: one pixel; cv_pi/180: 1 radian; 100: Minimum number of points above the detection line;: houghlines (DST, lines, 1, cv_pi/180,100, 0, 0); For (size_t I = 0; I <lines. size (); I ++) {float ROV = lines [I] [0], theta = lines [I] [1]; point pt1, pt2; double A = cos (theta), B = sin (theta); double X0 = A * Records, Y0 = B * records; pt1.x = cvround (x0 + 1000 * (-B); pt1.y = cvround (y0 + 1000 * ()); pt2.x = cvround (x0-1000 * (-B); pt2.y = cvround (y0-1000 * (a); line (cdst, pt1, pt2, scalar, 255), 3, cv_aa) ;}# else vector <vec4i> lines; // 50: minimum threshold value; 50: minimum length of a detection line; 10: maximum number of points between two points houghlinesp (DST, lines, 1, cv_pi/180, 50, 50, 10); 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 (0, 0, 255), 3, cv_aa) ;}# endif imshow ("Source", Src ); imshow ("detected lines", cdst); waitkey (); Return 0 ;}