OpenCv凸包缺陷 [英] OpenCv Convexity Defects
本文介绍了OpenCv凸包缺陷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过一些例子,我在网上找到使用opencv c ++ 2.4.4创建凸包。我正在调查使用凸面缺陷,但遇到了问题的这些类的C ++实现
我已经按照以下链接,因为它是最类似于我的问题,仍然没有运气。 使用c ++中的OpenCV 2.4计算凸度偏差
我收到以下错误。
openCV错误:Assertion failed(mtype == type0 ||(CV_MAT_CN(mtype)== 1&& 1<<< type0)& fixedDepthMask)!= 0))in create
按当前代码粘贴。
感谢您的任何帮助,
int c =
VideoCapture cap(0);
垫框架;
Mat边缘;
mat threshold_output;
cv :: vector< cv :: Vec4i>层次;
std :: vector< std :: vector< cv :: Point> >轮廓;
RNG rng(12345);
while(c!= 27)
{
cap>>帧;
cvtColor(frame,edges,CV_BGR2GRAY);
threshold(edges,threshold_output,100,255,CV_THRESH_OTSU);
findContours(threshold_output,contour,hierarchy,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_SIMPLE,cv :: Point(0,0));
std :: vector< Vec4i>缺陷;
vector< cv :: vector< int> > hull(contours.size());
for(int i = 0; i {
convexHull(contoururs [i],hull [i],false);
if(contoururs [i] .size()> 3)
{
convexityDefects(contoururs [i],hull [i],defects [i]);
}
}
}
解决方案>
std :: vector< Vec4i>缺陷;
应为
std :: vector< std :: vector< Vec4i> > defect(contours.size());
(每个轮廓/船体一个)
I am working through some examples I have found online to create convex hulls using opencv c++ 2.4.4. I was looking into using convexity defects but am running into issues with the c++ implementation of these classes
I have followed the link below as it is the most similar to my issue but still no luck. Calculating convexityDefects using OpenCV 2.4 in c++
I am recieving the error below.
openCV Error: Assertion failed (mtype == type0 || (CV_MAT_CN(mtype) == 1 && ((1 << type0) & fixedDepthMask) != 0)) in create
Additionally I have pasted by current code below.
Thank you for any help,
int c = 0;
VideoCapture cap(0);
Mat frame;
Mat edges;
Mat threshold_output;
cv::vector<cv::Vec4i> hierarchy;
std::vector<std::vector<cv::Point> > contours;
RNG rng(12345);
while( c != 27)
{
cap >> frame;
cvtColor(frame, edges, CV_BGR2GRAY);
threshold(edges, threshold_output, 100, 255, CV_THRESH_OTSU );
findContours( threshold_output, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0));
std::vector<Vec4i> defects;
vector<cv::vector<int> >hull( contours.size() );
for (int i = 0; i < contours.size(); i++)
{
convexHull(contours[i], hull[i], false );
if (contours[i].size() >3 )
{
convexityDefects(contours[i], hull[i], defects[i]);
}
}
}
解决方案
std::vector<Vec4i> defects;
should be
std::vector< std::vector<Vec4i> > defects( contours.size() );
(one for each contour / hull)
这篇关于OpenCv凸包缺陷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文