opencvc++线检测封装类_第1页
opencvc++线检测封装类_第2页
opencvc++线检测封装类_第3页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论