Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. cvtColor(crop, crop, CV_RGB2GRAY);
  2. adaptiveThreshold(crop, crop, 255, CV_ADAPTIVE_THRESH_MEAN_C,CV_THRESH_BINARY, 31, 15);
  3. Mat dst1, cdst1;
  4. Canny(crop, dst1, 50, 200, 3);
  5. cvtColor(dst1, cdst1, CV_GRAY2BGR);
  6.  
  7. vector<Vec2f> lines;
  8. // detect lines
  9. HoughLines(dst1, lines, 1, CV_PI/180, 200, 0, 0 );
  10. //HoughLinesP(dst1, lines, 1, CV_PI/180, 150, 0, 0);
  11.  
  12. // draw lines
  13. for( size_t i = 0; i < lines.size(); i++ )
  14. {
  15. float rho = lines[i][0], theta = lines[i][1];
  16. //if( theta>CV_PI/180*170 || theta<CV_PI/180*10){
  17. Point pt1, pt2;
  18. double a = cos(theta), b = sin(theta);
  19. double x0 = a*rho, y0 = b*rho;
  20. pt1.x = cvRound(x0 + 1000*(-b));
  21. pt1.y = cvRound(y0 + 1000*(a));
  22. pt2.x = cvRound(x0 - 1000*(-b));
  23. pt2.y = cvRound(y0 - 1000*(a));
  24. line( cdst1, pt1, pt2, Scalar(0,0,255), 3, CV_AA);
  25. //}
  26. }
  27. namedWindow("detected lines",WINDOW_NORMAL);
  28. imshow("detected lines", cdst1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement