ConvexHull OpenCV上的填充颜色

ConvexHull OpenCV上的填充颜色,opencv,colors,convex-hull,Opencv,Colors,Convex Hull,各位,请帮帮我。我有个问题。 我从图像中进行凸包检测 然后,我有一个问题,在ConvexHull边界内的区域上填充颜色 是否有人可以帮我在Convxhull边界内的区域填充颜色? 请帮助我实现源代码 我使用OpenCV 2.3 这是一个源代码: #include "stdafx.h" #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include <iostream>

各位,请帮帮我。我有个问题。 我从图像中进行凸包检测

然后,我有一个问题,在ConvexHull边界内的区域上填充颜色

是否有人可以帮我在Convxhull边界内的区域填充颜色?

请帮助我实现源代码

我使用OpenCV 2.3

这是一个源代码:

 #include "stdafx.h" 
 #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 = 240;
 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( "kubis1.jpg", 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 );
 }
#包括“stdafx.h”
#包括“opencv2/highgui/highgui.hpp”
#包括“opencv2/imgproc/imgproc.hpp”
#包括
#包括
#包括
使用名称空间cv;
使用名称空间std;
Mat-src;Mat src_gray;
int thresh=240;
int max_thresh=255;
RNG RNG(12345);
///函数头
无效阈值回调(int,void*);
/**@主功能*/
int main(int argc,字符**argv)
{
///加载源图像并将其转换为灰色
src=imread(“kubis1.jpg”,1);
///将图像转换为灰色并使其模糊
CVT颜色(src、src_灰色、CV_BGR2灰色);
模糊(src_灰,src_灰,大小(3,3));
///创建窗口
char*source\u window=“source”;
namedWindow(源窗口、CV窗口、自动调整大小);
imshow(源窗口,src);
createTrackbar(“阈值:”、“源”、&thresh、最大阈值、阈值回调);
thresh_回调(0,0);
等待键(0);
返回(0);
}
/**@function thresh\u回调*/
无效阈值回调(int,void*)
{
Mat src_copy=src.clone();
Mat阈值输出;
矢量等值线;
向量层次;
///使用阈值检测边缘
阈值(src_灰度,阈值_输出,阈值,255,阈值_二进制);
///寻找轮廓
findContours(阈值输出、轮廓、层次、CV树、CV链近似、点(0,0));
///查找每个轮廓的凸面外壳对象
向量壳(contours.size());
对于(int i=0;i
您应该使用带有负“厚度”参数的函数:

如果厚度>=0或
填充轮廓边界区域(如果是厚度),您有什么问题?我的问题:帮助我在ConvexHull边界内的区域上填充颜色。