


下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、opencvc+ 线检测封装类/各位拿的时候请注明博客地址#ifndef OPENCVLinesDetector_HPP#define OPENCVLinesDetector_HPP#include AbstractLinesDetector.hppnamespace doppia class OpenCvLinesDetector: public AbstractLinesDetectorpublic:OpenCvLinesDetector();OpenCvLinesDetector(const float input_image_threshold,const float directio
2、n_resolution, const float origin_resolution,const int detection_threshold);OpenCvLinesDetector();void operator()(const source_view_t &src, lines_t &lines);protected:/ 0 to 255,input_image pixels below this value are considered as 0const float input_image_threshold;const float direction_resolution;co
3、nst float origin_resolution;const int detection_threshold; / namespace doppia#endif / OPENCVLinesDetector_HPPAnd cpp#include OpenCvLinesDetector.hpp#include #include #include #include #include namespace doppia using namespace std;OpenCvLinesDetector:OpenCvLinesDetector():input_image_threshold(150),d
4、irection_resolution(M_PI/180)*1),origin_resolution(1),detection_threshold(50)/ nothing to do herereturn;OpenCvLinesDetector:OpenCvLinesDetector(const float input_image_threshold_,const float direction_resolution_, const float origin_resolution_,const int detection_threshold_): input_image_threshold(
5、input_image_threshold_),direction_resolution(direction_resolution_),origin_resolution(origin_resolution_),detection_threshold(detection_threshold_)/ nothing to do herereturn;OpenCvLinesDetector:OpenCvLinesDetector()/ nothing to do herereturn;void OpenCvLinesDetector:operator()(const source_view_t &s
6、rc, lines_t &lines)using namespace boost:gil;/ convert to opencv format -opencv:ipl_image_wrapper src_img = opencv:create_ipl_image(src);cv:Mat input_image(src_img.get();const double threshold_value = input_image_threshold; / 0 to 255const double max_value = 255;const int threshold_type = cv:THRESH_
7、TOZERO; / any value bellow the threshold_value is set to zerocv:threshold(input_image, input_image, threshold_value, max_value, threshold_type);/ call opencv -vector found_lines;const float rho_scale = 1;const float theta_scale = 1;/ rho: distance resolution of the accumulator in pixelsconst double
8、rho = origin_resolution*rho_scale;/ theta: angle resolution of the accumulator in radiansconst double theta = direction_resolution*theta_scale;/ threshold: the accumulator threshold parameter. Only those lines are returned that get enough votesconst int threshold = detection_threshold;/cv:HoughLines
9、(input_image, found_lines, rho, theta, threshold, rho_scale, theta_scale);cv:HoughLines(input_image, found_lines, rho, theta, threshold);/ convert to output format -lines.clear();for(std:size_t i=0; i found_lines.size(); i+=1)line_t t_line;const float rho = found_linesi0;const float theta = found_li
10、nesi1;double sin_theta, cos_theta;sincos(theta, &sin_theta, &cos_theta);if(sin_theta = 0)/ we simply skip this value (is this such a good idea ?)continue;/throw std:runtime_error(OpenCvLinesDetector:operator division by zero);/ 理论见维基百科t_line.direction()(0) = - cos_theta / sin_theta;t_line.origin()(0
11、) = rho / sin_theta;lines.push_back(t_line);const bool show_found_lines = false;if(show_found_lines)if(show_found_lines)cv:Mat src_img_mat(src_img.get(), color_image;cv:cvtColor(src_img_mat, color_image, CV_GRAY2RGB);const size_t max_lines_to_draw = 1;/5; / 20for(size_t i = 0;i std:min(found_lines.s
12、ize(), max_lines_to_draw); i+=1)CvPoint pt1, pt2;const bool draw_final_lines = true;if(draw_final_lines)const line_t &t_line = lines.at(i);pt1.x = 0;pt1.y = t_line.origin()(0);pt2.x = 1000;pt2.y = pt1.y + pt2.x * t_line.direction()(0);else/ use opencv lines instead of final linesconst cv:Vec2f &t_li
13、ne = found_lines.at(i);const float rho = t_line0;const float theta = t_line1;const double cos_theta = cos(theta), sin_theta = sin(theta);const double x0 = cos_theta*rho, y0 = sin_theta*rho;pt1.x = cvRound(x0 + 1000*(-sin_theta);pt1.y = cvRound(y0 + 1000*(cos_theta);pt2.x = cvRound(x0 - 1000*(-sin_theta);pt2.y = cvRound(y0 - 1000*(cos_theta);const int thickness = 1;cv:line( color_ima
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 旅游体验、地方认同及文化认同关系研究
- 舟曲县东山镇乡村人居环境优化研究
- 核心素养理念下语境教学法在中职英语词汇教学中的应用研究
- 留置胃管的护理查房
- 颌下腺护理常规课件
- 法制副校长教育职责与实施路径
- 老年人颈椎病病例讨论
- 颅骨骨折说课课件
- 温病学诊断要点
- 顺产护理课件
- 第38届中国化学奥林匹克(决赛)第二场参考案
- 生态水利工程学的研究范式创新与实践需求分析
- SJG 130 – 2023《混凝土模块化建筑技术规程》
- DB37-T5321-2025 居住建筑装配式内装修技术标准
- 《视网膜色素变性》课件示例
- 2025-2030中国火箭发动机行业市场发展趋势与前景展望战略分析研究报告
- T-CHSA 090-2024 年轻恒牙根尖诱导成形术操作专家共识
- 区块链在虚拟电厂分布式能源管理中的应用-全面剖析
- 贵州企业招聘2025贵州贵旅国际旅行服务有限公司招聘笔试参考题库附带答案详解
- 《公路工程施工组织设计》教案全套(54课时)项目1.1 公路建设的内容和特点-项目9指导性施工组织设计构成及编制
- 2024年广东江门广雅中学自主招生数学试卷真题(含答案详解)
评论
0/150
提交评论