我已经实现了使用fastcv查找和绘制最大轮廓的代码。但我没有得到实际的输出。找到最大轮廓是好的。但是绘制最大轮廓并没有给出结果。请任何建议。
unsigned int maxNumContours = 1000;
unsigned int size = 0;
unsigned int sizeOfPointBuffer = 0;
unsigned int maxPoints= ((2*ImgWidth) + (2 * ImgHeight));
//Actual Found Contour
unsigned int pNumContours = 0;
//Total Number of Points in Each Contour
unsigned int pNumContourPoints[1000] = {0};
//Pointer to Start of All Contour
unsigned int *pContourStartPointsfind[1000];
size = (maxPoints * sizeof(unsigned int));
sizeOfPointBuffer = (1000 * 2 * maxPoints * sizeof(unsigned int));
unsigned int *pPointBuffer=(unsigned int *)malloc(sizeOfPointBuffer);
memset(pPointBuffer,0,sizeOfPointBuffer);
int32_t hierarchy[1000][4];
fcvFindContoursExternalu8(mGr.data,ImgWidth,ImgHeight,ImgWidth,maxNumContours,&pNumContours,pNumContourPoints,pContourStartPointsfind,pPointBuffer,sizeOfPointBuffer,hierarchy,fcvFindContoursAllocate(ImgWidth));
__android_log_print(ANDROID_LOG_INFO, "JNI PART", "pNumContours = %d \n",pNumContours);
/*for(int j = 0; j < 5; j++){
__android_log_print(ANDROID_LOG_INFO, "JNI PART", "Number of Points in [%d] = %u \n",j, pNumContourPoints[j]);
}*/
int maxContour = pNumContourPoints[0];
int maxIndex = 0;
for(int j = 1; j < pNumContours; j++){
if(pNumContourPoints[j] > maxContour){
maxContour = pNumContourPoints[j];
maxIndex = j;
}
}
/*unsigned int *pContourStartPointsdraw[1000];
for(int i = 0; i < pNumContours; i++){
pContourStartPointsdraw[i] = pContourStartPointsfind[i];
}*/
unsigned int holeflag1[1] = {0};
unsigned int maxDraw[1] = {0};
maxDraw[0] = pNumContourPoints[maxIndex];
unsigned int *pContourStartPointsdraw[1] = {0};
pContourStartPointsdraw[0] = pContourStartPointsfind[maxIndex];
unsigned int pointDrawBufferSize = (pNumContourPoints[maxIndex]);
__android_log_print(ANDROID_LOG_INFO, "JNI PART", "pNumContourPoints[maxIndex] :: %d\n",pNumContourPoints[maxIndex]);
unsigned int *dummyPointer = pPointBuffer;
dummyPointer = pContourStartPointsfind[maxIndex];
unsigned int *pointBufferForDraw = (unsigned int *)malloc(pointDrawBufferSize);
memset(pointBufferForDraw, 0, pointDrawBufferSize);
memcpy(pointBufferForDraw, dummyPointer, pointDrawBufferSize);
/*for(int k = 0; k < pNumContourPoints[maxIndex]; k++) {
__android_log_print(ANDROID_LOG_INFO, "JNI PART", "Value of K:: %d\t",k);
__android_log_print(ANDROID_LOG_INFO, "JNI PART", "Value at PointBuffer:: %d\n",pointBufferForDraw[k]);
}*/
fcvDrawContouru8(mContourImg.data,ImgWidth,ImgHeight,ImgWidth,1,holeflag1,maxDraw,(const unsigned int **)pContourStartPointsdraw,pointDrawBufferSize,pointBufferForDraw,&hierarchy[maxIndex],0,2,125,125);