Advertisement
Guest User

openCv

a guest
Apr 5th, 2015
547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include "opencv2/highgui/highgui.hpp"
  2. #include "opencv2/imgproc/imgproc.hpp"
  3. #include <iostream>
  4.  
  5. void help()
  6. {
  7.     std::cout << "\nThis program demonstrates line finding with the Hough transform.\n"
  8.         "Usage:\n"
  9.         "./houghlines <image_name>, Default is pic1.jpg\n" << std::endl;
  10.     system("pause");
  11. }
  12.  
  13. int  main(int argc, char** argv)
  14. {
  15.     //const char* filename = argc >= 2 ? argv[1] : "C:\temp\test.jpg";
  16.     const char* filename = "C://temp//test3.jpg";
  17.     std::cout << "OpenCV Version: " << CV_VERSION << std::endl;
  18.     //IplImage* img = cvLoadImage("c://frame_201.bmp");
  19.     cv::Mat src = cv::imread(filename, 0);
  20.    
  21.     if (src.empty())
  22.     {
  23.         help();
  24.         std::cout << "can not open " << filename << std::endl;
  25.         return -1;
  26.     }
  27.    
  28.     cv::Mat dst, cdst;
  29.     cv::Canny(src, dst, 100, 300, 3);
  30.     cv::cvtColor(dst, cdst, cv::COLOR_GRAY2BGR);
  31.  
  32.     std::vector<cv::Vec4i> lines;
  33.     //
  34.     HoughLinesP(dst, lines, 1, CV_PI / 2, 200, 200, 5);
  35.     for (size_t i = 0; i < lines.size(); i++)
  36.     {
  37.         cv::Vec4i l = lines[i];
  38.         line(cdst, cv::Point(l[0], l[1]), cv::Point(l[2], l[3]), cv::Scalar(0, 0, 255), 3, cv::LINE_AA);
  39.     }
  40.     imshow("source", src);
  41.     imshow("detected lines", cdst);
  42.     cv::imwrite("LineDetection.jpg", cdst);
  43.     cv::waitKey();
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement