-1

我正在对静态手势进行 KNN 分类,但出现此错误。

错误:NUIGHR.exe 中 0x01213aa2 处的未处理异常:0xC0000005:访问冲突读取位置 0x00000000。

CvMat* GetFeatures(CvSeq* contour, CvSeq* hull, double boundingRectArea){
CvMoments moments;
CvHuMoments humoments;
cvMoments(contour, &moments, cvGetHuMoments(&moments, &humoments);

int cCont;
double cArea, cPerimeter, cDiameter, cExtent, cCompactness, cEccentricity, cCircularity;

cCont         = contour->total;
cArea         = fabs(cvContourArea(contour));
cPerimeter    = cvContourPerimeter(contour);
cDiameter     = sqrt( 4 * cArea / CV_PI);
cExtent       = cArea / (boundingRectArea * boundingRectArea);
cCompactness  = (4 * cArea * CV_PI) / cPerimeter;
cEccentricity = pow( (moments.m20 - moments.m02), 2) - (4 * pow(moments.m11, 2)) / ( pow(moments.m20 + moments.m02, 2) );
cCircularity = pow(cPerimeter, 2) / cArea;

cvmSet( featureVector, 0, 0,  boundingRectArea);
cvmSet( featureVector, 0, 1,  cCont);
cvmSet( featureVector, 0, 2,  cArea);
cvmSet( featureVector, 0, 3,  cPerimeter);
cvmSet( featureVector, 0, 4,  cDiameter);
cvmSet( featureVector, 0, 5,  cExtent);
cvmSet( featureVector, 0, 6,  cCompactness);
cvmSet( featureVector, 0, 7,  cEccentricity);
cvmSet( featureVector, 0, 8,  cCircularity);
cvmSet( featureVector, 0, 9,  humoments.hu1);
cvmSet( featureVector, 0, 10, humoments.hu2);
cvmSet( featureVector, 0, 11, humoments.hu3);
cvmSet( featureVector, 0, 12, humoments.hu4);
cvmSet( featureVector, 0, 13, humoments.hu5);
cvmSet( featureVector, 0, 14, humoments.hu6);
cvmSet( featureVector, 0, 15, humoments.hu7);

return featureVector;
}
int main(){
...
const int K = 10;
CvKNearest *knn = NULL;
float resultNode = 0;
CvMat* featVector = cvCreateMat(1, NUMBER_OF_FEATURES, CV_32FC1 );
CvMat* nearest = cvCreateMat(1, K, CV_32FC1);
...
resultNode = knn->find_nearest(&featVector, K, 0, 0, nearest, 0);
}

我想我需要将 CvMat* 转换为 CvMat。我该怎么做?

4

2 回答 2

0

featureVector = NULL 指针对不起,伙计们...我是初学者:(

于 2012-09-26T23:42:23.017 回答
0

您不能将 0 作为第 3 和第 4 个参数传递给 find_nearest 函数,如果您确实将某些东西作为第 5 个参数传递,则不能。OpenCV 尝试填充结果和 neighbourResponses(请参阅 doc),但无法读取/写入 NULL 指针。

于 2012-09-25T21:46:35.420 回答