imgproc_HoughLinesP.cpp 769 B

12345678910111213141516171819202122232425262728293031
  1. #include <opencv2/imgproc.hpp>
  2. #include <opencv2/highgui.hpp>
  3. using namespace cv;
  4. using namespace std;
  5. int main(int argc, char** argv)
  6. {
  7. Mat src, dst, color_dst;
  8. if( argc != 2 || !(src=imread(argv[1], 0)).data)
  9. return -1;
  10. Canny( src, dst, 50, 200, 3 );
  11. cvtColor( dst, color_dst, COLOR_GRAY2BGR );
  12. vector<Vec4i> lines;
  13. HoughLinesP( dst, lines, 1, CV_PI/180, 80, 30, 10 );
  14. for( size_t i = 0; i < lines.size(); i++ )
  15. {
  16. line( color_dst, Point(lines[i][0], lines[i][1]),
  17. Point( lines[i][2], lines[i][3]), Scalar(0,0,255), 3, 8 );
  18. }
  19. namedWindow( "Source", 1 );
  20. imshow( "Source", src );
  21. namedWindow( "Detected Lines", 1 );
  22. imshow( "Detected Lines", color_dst );
  23. waitKey(0);
  24. return 0;
  25. }