一杯清酒邀明月
天下本无事,庸人扰之而烦耳。
posts - 3121,comments - 209,views - 578万

 

复制代码
 1 #include "opencv2/highgui/highgui.hpp"
 2 #include "opencv2/imgproc/imgproc.hpp"
 3 
 4 #include <iostream>
 5 
 6 using namespace cv;
 7 using namespace std;
 8 
 9 void help()
10 {
11  cout << "\nThis program demonstrates line finding with the Hough transform.\n"
12          "Usage:\n"
13          "./houghlines <image_name>, Default is pic1.jpg\n" << endl;
14 }
15 
16 int main(int argc, char** argv)
17 {
18  const char* filename = argc >= 2 ? argv[1] : "pic1.jpg";
19 
20  Mat src = imread(filename, 0);
21  if(src.empty())
22  {
23      help();
24      cout << "can not open " << filename << endl;
25      return -1;
26  }
27 
28  Mat dst, cdst;
29  Canny(src, dst, 50, 200, 3);
30  cvtColor(dst, cdst, CV_GRAY2BGR);
31 
32  #if 0
33   vector<Vec2f> lines;
34   HoughLines(dst, lines, 1, CV_PI/180, 100, 0, 0 );
35 
36   for( size_t i = 0; i < lines.size(); i++ )
37   {
38      float rho = lines[i][0], theta = lines[i][1];
39      Point pt1, pt2;
40      double a = cos(theta), b = sin(theta);
41      double x0 = a*rho, y0 = b*rho;
42      pt1.x = cvRound(x0 + 1000*(-b));
43      pt1.y = cvRound(y0 + 1000*(a));
44      pt2.x = cvRound(x0 - 1000*(-b));
45      pt2.y = cvRound(y0 - 1000*(a));
46      line( cdst, pt1, pt2, Scalar(0,0,255), 3, CV_AA);
47   }
48  #else
49   vector<Vec4i> lines;
50   HoughLinesP(dst, lines, 1, CV_PI/180, 50, 50, 10 );
51   for( size_t i = 0; i < lines.size(); i++ )
52   {
53     Vec4i l = lines[i];
54     line( cdst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0,0,255), 3, CV_AA);
55   }
56  #endif
57  imshow("source", src);
58  imshow("detected lines", cdst);
59 
60  waitKey();
61 
62  return 0;
63 }
复制代码
posted on   一杯清酒邀明月  阅读(225)  评论(0编辑  收藏  举报
编辑推荐:
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
阅读排行:
· 全网最简单!3分钟用满血DeepSeek R1开发一款AI智能客服,零代码轻松接入微信、公众号、小程
· .NET 10 首个预览版发布,跨平台开发与性能全面提升
· 《HelloGitHub》第 107 期
· 全程使用 AI 从 0 到 1 写了个小工具
· 从文本到图像:SSE 如何助力 AI 内容实时呈现?(Typescript篇)
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示