OpenCV 显示图像的凸包 Convex Hull 效果
来源:互联网 发布:c语言bool类型 编辑:程序博客网 时间:2024/06/08 14:02
OpenCV 显示图像的凸包 Convex Hull 效果
目的
本文将教你如何使用 OpenCV 函数 convexHull
代码
代码如下所示,可从这里 下载
#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 header void 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( " Threshold:", "Source", &thresh, max_thresh, thresh_callback ); thresh_callback( 0, 0 ); waitKey(0); return(0); } /** @function thresh_callback */ void thresh_callback(int, void* ) { Mat src_copy = src.clone(); Mat threshold_output; vector<vector<Point> > contours; vector<Vec4i> hierarchy; /// Detect edges using Threshold threshold( src_gray, threshold_output, thresh, 255, THRESH_BINARY ); /// Find contours findContours( threshold_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) ); /// Find the convex hull object for each contour vector<vector<Point> >hull( contours.size() ); for( int i = 0; i < contours.size(); i++ ) { convexHull( Mat(contours[i]), hull[i], false ); } /// Draw contours + hull results Mat drawing = Mat::zeros( threshold_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, 1, 8, vector<Vec4i>(), 0, Point() ); drawContours( drawing, hull, i, color, 1, 8, vector<Vec4i>(), 0, Point() ); } /// Show in a window namedWindow( "Hull demo", CV_WINDOW_AUTOSIZE ); imshow( "Hull demo", drawing ); }
结果
0 0
- OpenCV 显示图像的凸包 Convex Hull 效果
- 二维凸包convex hull之C++及OpenCV实现
- 二维凸包convex hull之C++及OpenCV实现
- 凸包(convex hull)
- 凸包(Convex hull)
- 凸包(Convex Hull)
- 寻找凸包 convex hull(一)
- MATLAB凸包Convex hull运算
- 凸包问题Finding the convex hull
- zoj 3871 Convex Hull(凸包)
- opencv学习-imgprocess-凸包函数Convex Hull和boundingRect以及minEnclosingCircle
- hdu3662 +3D Convex Hull+三维凸包的表面多边形个数
- 凸包(Convex Hull)问题的三种解法: 暴力,Graham Scan,分治
- POJ1113 Convex Hull/凸包 Graham scan算法
- UVa 681 Convex Hull Finding (凸包,Graham‘s Scan)
- POJ 3787 Convex Hull of Lattice Points(凸包)
- UVA 681 Convex Hull Finding【逆时针输出凸包顶点】
- 三维凸包模板_HDU 3662 3D Convex Hull
- vlc缓冲事件添加及缓冲进度
- sql基本语句
- 【English】The Summer in July
- 开心网某站存在远程命令执行漏洞涉及项目源码(ImageMagick补丁绕过)
- CUDA学习笔记一:CUDA+OpenCV的图像转置,采用Shared Memory进行CUDA程序优化
- OpenCV 显示图像的凸包 Convex Hull 效果
- windbg停在无符号驱动的DriverEntry(WIN10)
- Shell编程---变量
- 题目477 A+B Problem III
- 隐藏帧---javaScript+iframe模仿ajax的点上通讯
- HDU-5775-Bubble Sort(线段树)
- 如何写出复杂业务查询的sql语句
- Android抓取log文件的方法
- HDU 5763 Another Meaning(多校4)