Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cvtColor(crop, crop, CV_RGB2GRAY);
- adaptiveThreshold(crop, crop, 255, CV_ADAPTIVE_THRESH_MEAN_C,CV_THRESH_BINARY, 31, 15);
- Mat dst1, cdst1;
- Canny(crop, dst1, 50, 200, 3);
- cvtColor(dst1, cdst1, CV_GRAY2BGR);
- vector<Vec2f> lines;
- // detect lines
- HoughLines(dst1, lines, 1, CV_PI/180, 200, 0, 0 );
- //HoughLinesP(dst1, lines, 1, CV_PI/180, 150, 0, 0);
- // draw lines
- for( size_t i = 0; i < lines.size(); i++ )
- {
- float rho = lines[i][0], theta = lines[i][1];
- //if( theta>CV_PI/180*170 || theta<CV_PI/180*10){
- Point pt1, pt2;
- double a = cos(theta), b = sin(theta);
- double x0 = a*rho, y0 = b*rho;
- pt1.x = cvRound(x0 + 1000*(-b));
- pt1.y = cvRound(y0 + 1000*(a));
- pt2.x = cvRound(x0 - 1000*(-b));
- pt2.y = cvRound(y0 - 1000*(a));
- line( cdst1, pt1, pt2, Scalar(0,0,255), 3, CV_AA);
- //}
- }
- namedWindow("detected lines",WINDOW_NORMAL);
- imshow("detected lines", cdst1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement