绘制凸度缺陷C OPENCV
Drawing Convexity Defects C++ OpenCV
从下面的代码中,我能够用标记为小圆圈的质心画出最大的轮廓,将船体标记为黄线。如何绘制凸性缺陷?我应该使用circle()函数或drawContours()函数吗?
Mat bw;
Mat canny_output;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours( bw, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
int s = getBiggestContour(contours);
Mat drawing = Mat::zeros( src.size(), CV_8UC3 ); //UC1
Point2f mc = getCentroidPoint(contours[s]);
drawContours( drawing, contours, s, Scalar(255,255,255), -1, 8, hierarchy, 0, Point() );
circle( drawing, mc, 4, Scalar(0,0,255), 1, 8, 0 );
vector<vector<Point> >hull( contours[s].size() );
convexHull( Mat(contours[s]), hull[s], false );
drawContours( drawing, hull, s, Scalar(0,255,255), 1, 8, vector<Vec4i>(), 0, Point() );
上面的代码有效,但只有一个轮廓要使用,这是最大的轮廓,因此我认为将vector>用于船体的轮廓太多了。我该如何简化?
下面的代码来自另一个Stackoverflow问题,但并未显示如何在将凸缺损绘制到垫子图像上使用缺陷变量。如何实现?
vector<vector<int> > hullsI(contours.size());
vector<vector<Point> > hullsP(contours.size());
vector<vector<Vec4i> > defects(contours.size());
for(int i = 0; i <contours.size(); ++i){
//find the hulls
convexHull(contours[i], hullsI[i], false, false);
convexHull(contours[i], hullsP[i], false, true);
//find the defects
if (contours[i].size() >3 ){
convexityDefects(contours[i], hullsI[i], defects[i]);
}
}
我不想使用iPlimage。我更喜欢垫子。
您可以使用'cvdrawContours()'绘制凸赫尔操作的结果,但是您确实需要正确设置参数,以实现这一目标。我有一个示例,但它使用" cvconvexhull2()"和iplimages,但是它应该以垫子和其他凸操作的方式工作:
IplImage* src; //the image where the contours are detected on
IplImage frm; //the image you want the results to be drawn on
CvMemStorage* storage = cvCreateMemStorage(0);
CvSeq* contours = NULL;
cvFindContours(src, storage, &contours, sizeof (CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
for (CvSeq* c = contours; c != NULL; c = c->h_next) {
CvSeq* dest = NULL;
CvMemStorage* hullStorage = cvCreateMemStorage(0);
dest = cvConvexHull2(c, hullStorage, CV_CLOCKWISE, 1);
cvDrawContours(frm, dest, cvScalarAll(255), cvScalarAll(255), 0, 2, 8);
cvReleaseMemStorage(&hullStorage);
}
cvReleaseMemStorage(&storage);
相关文章:
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 尝试导入pybind-opencv模块时出现libgtk错误
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 将OpenCV C++重写为EmguCV C#-如何使用指针
- OpenCV C++.快速计算混淆矩阵
- 在C++代码中包含opencv时,使用ctypes创建.so文件
- 绘制凸度缺陷C OPENCV
- 在opencv中发现凸性缺陷?[崩溃取决于给定的输入图像]
- OpenCv 凸性缺陷
- OpenCV-消除凸性缺陷(Python到C++)
- OpenCV和凸面缺陷
- 在opencv c++函数中查找凸性缺陷点
- 一个c++凹凸缺陷包装器(OpenCV)
- 寻找凸缺陷?在OpenCV 2.3, c++和MS Visual Studio2010中
- 如何从OpenCV的凹凸缺陷点画出最小的圆
- 凹凸性缺陷c++ OpenCv
- OpenCv凹凸性缺陷
- OpenCV凹凸缺陷绘图