gpt4 book ai didi

c++ - C++ convexityDefects 包装器(OpenCV)?

转载 作者:行者123 更新时间:2023-11-28 03:44:01 34 4
gpt4 key购买 nike

我正在尝试为 OpenCV 创建一个 C++ 包装器,但不幸的是无法让它工作。我一次又一次地收到同样的错误:“OpenCV 错误:参数错误(凸包既不是序列也不是矩阵)”。我真的不明白为什么。

代码如下:

   void convexityDefects (vector <vector<Point> > contour, vector <vector<int> > convexHullPoints, vector <vector<Point> > *convexHullDefects)
{
CvSeq *contourSeq;
CvSeq *convexHullDefectsSeq;
CvSeq *convexHullSeq;

CvMemStorage *contourSeqStorage = cvCreateMemStorage (0);
CvMemStorage *convexHullSeqStorage = cvCreateMemStorage (0);
CvMemStorage *convexHullDefectsSeqStorage = cvCreateMemStorage (0);
CvMemStorage *cvConvexityDefectsStorage = cvCreateMemStorage (0);

contourSeq = cvCreateSeq (CV_SEQ_KIND_GENERIC | CV_32SC2, sizeof (CvSeq), sizeof (CvPoint), contourSeqStorage);
convexHullDefectsSeq = cvCreateSeq (CV_SEQ_KIND_GENERIC, sizeof (CvSeq), sizeof (CvPoint), convexHullDefectsSeqStorage);
convexHullSeq = cvCreateSeq (CV_SEQ_KIND_GENERIC, sizeof (CvSeq), sizeof (int), convexHullSeqStorage);

for (int counter = 0; counter < contour.at (0).size (); counter ++)
{
CvPoint element = {contour.at (0).at (counter).x, contour.at (0).at (counter).y};
cvSeqPush (contourSeq, &element);
}

int hullArray [convexHullPoints.at (0).size ()];

for (int counter = 0; counter < convexHullPoints.size (); counter ++)
{
hullArray [counter] = convexHullPoints.at (0).at (counter);
}

for (int counter = 0; counter < convexHullPoints.size (); counter ++)
{
cvSeqPush (convexHullSeq, &(hullArray [counter]));
}

convexHullDefectsSeq = cvConvexityDefects (contourSeq, &convexHullSeq, cvConvexityDefectsStorage);

CvConvexityDefect convexHullDefectsArray [convexHullDefectsSeq -> total];

cvCvtSeqToArray (convexHullDefectsSeq, &convexHullDefectsArray, CV_WHOLE_SEQ);

for (int counter = 0; counter < convexHullDefectsSeq -> total; counter ++)
{
CvPoint start = {convexHullDefectsArray [counter].start -> x, convexHullDefectsArray [counter].start -> y};
CvPoint depthPoint = {convexHullDefectsArray [counter].depth_point -> x, convexHullDefectsArray [counter].depth_point -> y};
CvPoint end = {convexHullDefectsArray [counter].end -> x, convexHullDefectsArray [counter].end -> y};

vector <Point> convexityDefectVector;
convexityDefectVector.push_back (start);
convexityDefectVector.push_back (depthPoint);
convexityDefectVector.push_back (end);

convexHullDefects -> push_back (convexityDefectVector);
}

cvReleaseMemStorage (&contourSeqStorage);
cvReleaseMemStorage (&convexHullSeqStorage);
cvReleaseMemStorage (&convexHullDefectsSeqStorage);
cvReleaseMemStorage (&cvConvexityDefectsStorage);
}

最佳答案

你应该看看this其他关于SO的帖子。看来他已经解决了这个问题。

关于c++ - C++ convexityDefects 包装器(OpenCV)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8249805/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com