반응형

참고:

http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html








  1. #include "opencv2/imgcodecs.hpp"  
  2. #include "opencv2/highgui/highgui.hpp"  
  3. #include "opencv2/imgproc/imgproc.hpp"  
  4.   
  5. #include <iostream>  
  6.   
  7. using namespace cv;  
  8. using namespace std;  
  9.   
  10.   
  11. int main(int argc, char** argv)  
  12. {  
  13.   
  14.     VideoCapture cap1(0);  
  15.   
  16.    // cap1.set(3,320);  
  17.   //  cap1.set(4,240);  
  18.   
  19.     if (!cap1.isOpened())  
  20.     {  
  21.         printf("카메라를 열수 없습니다. \n");  
  22.     }  
  23.   
  24.   
  25.     Mat frame0;  
  26.   
  27.   
  28.   
  29.     for (;;)  
  30.     {  
  31.         cap1 >> frame0;  
  32.         cvtColor(frame0, frame0, CV_BGR2GRAY);  
  33.   
  34.         Mat dst, cdst;  
  35.         Canny(frame0, dst, 50, 200, 3);  
  36.         cvtColor(dst, cdst, COLOR_GRAY2BGR);  
  37.   
  38.   
  39.         vector<Vec4i> lines;  
  40.         HoughLinesP(dst, lines, 1, CV_PI/180, 50, 50, 10 );  
  41.         forsize_t i = 0; i < lines.size(); i++ )  
  42.         {  
  43.             Vec4i l = lines[i];  
  44.             line( cdst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0,0,255),
  45.                   3, LINE_AA);  
  46.         }  
  47.   
  48.         imshow("original", frame0);  
  49.         imshow("houghline", cdst);  
  50.   
  51.   
  52.         if (waitKey(30) >= 0) break;  
  53.     }  
  54.   
  55.   
  56.     return 0;  
  57. }  



반응형

문제 발생시 지나치지 마시고 댓글 남겨주시면 가능한 빨리 답장드립니다.

도움이 되셨다면 토스아이디로 후원해주세요.
https://toss.me/momo2024


제가 쓴 책도 한번 검토해보세요 ^^

+ Recent posts