我正在研究一些在网上找到的示例,以使用 opencv c++ 2.4.4 创建凸包。我正在研究使用凸性缺陷,但遇到了这些类的 C++ 实现问题
我已经点击了下面的链接,因为它与我的问题最相似,但仍然没有运气。 Calculating convexityDefects using OpenCV 2.4 in c++
我收到以下错误。
openCV Error: Assertion failed (mtype == type0 || (CV_MAT_CN(mtype) == 1 && ((1 << type0) & fixedDepthMask) != 0)) in create
此外,我已在下面粘贴了当前代码。
感谢您的帮助,
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;
应该是
std::vector< std::vector<Vec4i> > defects( contours.size() );
(每个轮廓/船体一个)
关于c++ - OpenCv 凸性缺陷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15238862/