OpenCV 查找图像轮廓
来源:互联网 发布:淘宝能买到客户资料呢 编辑:程序博客网 时间:2024/05/17 22:02
OpenCV 查找图像轮廓
目的
我们将学习:
- 学会使用 OpenCV 函数 findContours
- 学会使用 OpenCV 函数 drawContours
原理
代码
下面是本示例的代码,可以从这里 下载
#include "opencv2/highgui/highgui.hpp"#include "opencv2/imgproc/imgproc.hpp"#include <iostream>#include <stdio.h>#include <stdlib.h>using namespace cv;using namespace std;Mat src; Mat src_gray;int thresh = 100;int max_thresh = 255;RNG rng(12345);/// Function headervoid thresh_callback(int, void* );/** @function main */int main( int argc, char** argv ){ /// Load source image and convert it to gray src = imread( argv[1], 1 ); /// Convert image to gray and blur it cvtColor( src, src_gray, CV_BGR2GRAY ); blur( src_gray, src_gray, Size(3,3) ); /// Create Window char* source_window = "Source"; namedWindow( source_window, CV_WINDOW_AUTOSIZE ); imshow( source_window, src ); createTrackbar( " Canny thresh:", "Source", &thresh, max_thresh, thresh_callback ); thresh_callback( 0, 0 ); waitKey(0); return(0);}/** @function thresh_callback */void thresh_callback(int, void* ){ Mat canny_output; vector<vector<Point> > contours; vector<Vec4i> hierarchy; /// Detect edges using canny Canny( src_gray, canny_output, thresh, thresh*2, 3 ); /// Find contours findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) ); /// Draw contours Mat drawing = Mat::zeros( canny_output.size(), CV_8UC3 ); for( int i = 0; i< contours.size(); i++ ) { Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) ); drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, Point() ); } /// Show in a window namedWindow( "Contours", CV_WINDOW_AUTOSIZE ); imshow( "Contours", drawing );}
解释
结果
0 0
- OpenCV 查找图像轮廓
- opencv--查找图像轮廓
- OpenCV:查找并绘制图像的轮廓
- opencv 查找轮廓 绘制轮廓
- opencv 图像的轮廓查找 滚动条函数设置查找轮廓
- OpenCV笔记10:用cvFindContours查找图像轮廓并显示
- 图像轮廓获取opencv
- opencv-图像轮廓
- OpenCV图像的轮廓
- opencv 图像轮廓
- opencv图像轮廓
- OpenCV检测图像轮廓
- opencv 图像轮廓处理
- OpenCV查找轮廓
- OpenCV笔记: 查找轮廓
- opencv查找轮廓
- opencv 轮廓查找 findContours
- Opencv轮廓查找检测
- ImageView定宽,高度等比例放大
- Linux线程同步-----条件变量
- oracle数据库删除操作
- dagger2简单使用
- 02-变量测试语句
- OpenCV 查找图像轮廓
- 项目之初:Pch文件里的配置.
- Java——操作ProtocolBuffer格式数据初步
- HDU 5775 Bubble Sort (多校4)
- iOS实战演练之——UINavigationBar滑动问题
- 准备写:创建对象时的内存分配
- IOS Dev Intro - Third Party Library Process
- GetLastError的返回值意思
- spring的HelloWorld<01>