当前位置: 首页 > news >正文

OpenCV中更稳更快的边缘检测方法,快速查找线、圆、椭圆--EdgeDrawing-C++代码

计算机视觉之家看到快速圆检测Edge Drawing,其效果比霍夫要好,速度更快(具体效果可以参考视觉之家的文章),上面C++代码不全,那么好的检测效果国内资料竟然那么少,后在opencv的开发文档中找到了C++代码,在此分享学习交流。

实战 | OpenCV中更稳更快的找圆方法--EdgeDrawing使用演示(详细步骤 + 代码)_opencv 找圆_计算机视觉之家的博客-CSDN博客

OpenCV: EdgeDrawing

OpenCV: fld_lines.cpp

#include <iostream>#include "opencv2/imgproc.hpp"
#include "opencv2/ximgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"using namespace std;
using namespace cv;
using namespace cv::ximgproc;int main(int argc, char** argv)
{string in;CommandLineParser parser(argc, argv, "{@input|corridor.jpg|input image}{help h||show help message}");if (parser.has("help")){parser.printMessage();return 0;}in = samples::findFile(parser.get<string>("@input"));Mat image = imread(in, IMREAD_GRAYSCALE);if( image.empty() ){return -1;}// Create FLD detector// Param               Default value   Description// length_threshold    10            - Segments shorter than this will be discarded// distance_threshold  1.41421356    - A point placed from a hypothesis line//                                     segment farther than this will be//                                     regarded as an outlier// canny_th1           50            - First threshold for//                                     hysteresis procedure in Canny()// canny_th2           50            - Second threshold for//                                     hysteresis procedure in Canny()// canny_aperture_size 3            - Aperturesize for the sobel operator in Canny().//                                     If zero, Canny() is not applied and the input//                                     image is taken as an edge image.// do_merge            false         - If true, incremental merging of segments//                                     will be performedint length_threshold = 10;float distance_threshold = 1.41421356f;double canny_th1 = 50.0;double canny_th2 = 50.0;int canny_aperture_size = 3;bool do_merge = false;Ptr<FastLineDetector> fld = createFastLineDetector(length_threshold,distance_threshold, canny_th1, canny_th2, canny_aperture_size,do_merge);vector<Vec4f> lines;// Because of some CPU's power strategy, it seems that the first running of// an algorithm takes much longer. So here we run the algorithm 10 times// to see the algorithm's processing time with sufficiently warmed-up// CPU performance.for (int run_count = 0; run_count < 5; run_count++) {double freq = getTickFrequency();lines.clear();int64 start = getTickCount();// Detect the lines with FLDfld->detect(image, lines);double duration_ms = double(getTickCount() - start) * 1000 / freq;cout << "Elapsed time for FLD " << duration_ms << " ms." << endl;}// Show found lines with FLDMat line_image_fld(image);fld->drawSegments(line_image_fld, lines);imshow("FLD result", line_image_fld);waitKey(1);Ptr<EdgeDrawing> ed = createEdgeDrawing();ed->params.EdgeDetectionOperator = EdgeDrawing::SOBEL;ed->params.GradientThresholdValue = 38;ed->params.AnchorThresholdValue = 8;vector<Vec6d> ellipses;for (int run_count = 0; run_count < 5; run_count++) {double freq = getTickFrequency();lines.clear();int64 start = getTickCount();// Detect edges//you should call this before detectLines() and detectEllipses()ed->detectEdges(image);// Detect linesed->detectLines(lines);double duration_ms = double(getTickCount() - start) * 1000 / freq;cout << "Elapsed time for EdgeDrawing detectLines " << duration_ms << " ms." << endl;start = getTickCount();// Detect circles and ellipsesed->detectEllipses(ellipses);duration_ms = double(getTickCount() - start) * 1000 / freq;cout << "Elapsed time for EdgeDrawing detectEllipses " << duration_ms << " ms." << endl;}Mat edge_image_ed = Mat::zeros(image.size(), CV_8UC3);vector<vector<Point> > segments = ed->getSegments();for (size_t i = 0; i < segments.size(); i++){const Point* pts = &segments[i][0];int n = (int)segments[i].size();polylines(edge_image_ed, &pts, &n, 1, false, Scalar((rand() & 255), (rand() & 255), (rand() & 255)), 1);}imshow("EdgeDrawing detected edges", edge_image_ed);Mat line_image_ed(image);fld->drawSegments(line_image_ed, lines);// Draw circles and ellipsesfor (size_t i = 0; i < ellipses.size(); i++){Point center((int)ellipses[i][0], (int)ellipses[i][1]);Size axes((int)ellipses[i][2] + (int)ellipses[i][3], (int)ellipses[i][2] + (int)ellipses[i][4]);double angle(ellipses[i][5]);Scalar color = ellipses[i][2] == 0 ? Scalar(255, 255, 0) : Scalar(0, 255, 0);ellipse(line_image_ed, center, axes, angle, 0, 360, color, 2, LINE_AA);}imshow("EdgeDrawing result", line_image_ed);waitKey();return 0;
}

相关文章:

  • 【深度学习环境】windows安装 NVIDIA Docker
  • 【python】9个python进阶技巧(实用)
  • Outlook如何删除邮箱账户
  • 石英增强光声光谱气体传感技术中的高精密压力控制解决方案
  • Redis学习笔记10:基于spring的Lettuce redis客户端Pipelining管道
  • centos7 yum安装python3.9时报错【没有可用软件包 python3.9。 错误:无须任何处理】
  • 开放领域问答机器人2——开发流程和方案
  • 【避雷选刊】Springer旗下2/3区,2个月录用!发文量激增,还能投吗?
  • 使用matlab实现图像信号的色彩空间转换
  • HslCommunication模拟西门子读写数据
  • 压测必经之路,Jmeter分布式压测教程!
  • 响应式摄影科技传媒网站模板源码带后台
  • 《未来之路:技术探索与梦想的追逐》
  • IntelliJ IDEA 2023.2.1 (Ultimate Edition) 版本 Git 如何找回被 Drop Commit 的提交记录
  • 移植LVGL到单片机的一个demo简单介绍
  • Akka系列(七):Actor持久化之Akka persistence
  • axios 和 cookie 的那些事
  • C++入门教程(10):for 语句
  • CAP理论的例子讲解
  • EventListener原理
  • JS实现简单的MVC模式开发小游戏
  • VUE es6技巧写法(持续更新中~~~)
  • Vue.js源码(2):初探List Rendering
  • Vue2.0 实现互斥
  • vue-loader 源码解析系列之 selector
  • 记一次用 NodeJs 实现模拟登录的思路
  • 利用阿里云 OSS 搭建私有 Docker 仓库
  • 嵌入式文件系统
  • 使用SAX解析XML
  • 想使用 MongoDB ,你应该了解这8个方面!
  • 走向全栈之MongoDB的使用
  • Android开发者必备:推荐一款助力开发的开源APP
  • hi-nginx-1.3.4编译安装
  • 移动端高清、多屏适配方案
  • ​MySQL主从复制一致性检测
  • ​ssh-keyscan命令--Linux命令应用大词典729个命令解读
  • ​TypeScript都不会用,也敢说会前端?
  • (C语言)字符分类函数
  • (附源码)springboot家庭装修管理系统 毕业设计 613205
  • (七)微服务分布式云架构spring cloud - common-service 项目构建过程
  • (三)elasticsearch 源码之启动流程分析
  • (顺序)容器的好伴侣 --- 容器适配器
  • (原創) 如何優化ThinkPad X61開機速度? (NB) (ThinkPad) (X61) (OS) (Windows)
  • (转)树状数组
  • (转)项目管理杂谈-我所期望的新人
  • ./mysql.server: 没有那个文件或目录_Linux下安装MySQL出现“ls: /var/lib/mysql/*.pid: 没有那个文件或目录”...
  • .bashrc在哪里,alias妙用
  • .NET 中选择合适的文件打开模式(CreateNew, Create, Open, OpenOrCreate, Truncate, Append)
  • .net6解除文件上传限制。Multipart body length limit 16384 exceeded
  • .netcore 如何获取系统中所有session_如何把百度推广中获取的线索(基木鱼,电话,百度商桥等)同步到企业微信或者企业CRM等企业营销系统中...
  • :如何用SQL脚本保存存储过程返回的结果集
  • @CacheInvalidate(name = “xxx“, key = “#results.![a+b]“,multi = true)是什么意思
  • [Apio2012]dispatching 左偏树
  • [ARC066F]Contest with Drinks Hard
  • [BZOJ 3282] Tree 【LCT】