I confused in using fcvFindContour
First I used fcvAdaptiveThresholdGaussian5x5u8 to get binary image, its works fine
then I wanted to get contour and drawing it, so use fcvFindContoursExternalu8, but this function requires bunch of parameters but all have is parameter src for binary image, so I created bunch of variables to fit that function paramaters, it seem no error in intellisense, but when I run it the app crashed.
this is my code, I using visual studio to create WP8 cpp project.
//convert to binary image fcvAdaptiveThresholdGaussian5x5u8(src,width,height,width,255,FCV_THRESH_BINARY,4,dst,width); //declaration variable to fill fcvFindContours parameters uint32_t * pNumContours=(uint32_t *)malloc(sizeof(*pNumContours)); uint32_t * pNumContourPoints=(uint32_t *)malloc(sizeof(*pNumContourPoints)); uint32_t **__restrict pContourStartPointsfind=(uint32_t **)malloc(sizeof(*pContourStartPointsfind)); const uint32_t **__restrict pContourStartPointsdraw =(const uint32_t **__restrict)malloc(sizeof(**pContourStartPointsdraw)) ; uint32_t * pPointBuffer=(uint32_t *)malloc(sizeof(*pPointBuffer)); int32_t hierarchy[30][4]; uint32_t * holeflag = (uint32_t *)malloc(sizeof(*holeflag)); fcvFindContoursExternalu8(dst,width,height,width,30,pNumContours,pNumContourPoints,pContourStartPointsfind,pPointBuffer,30,hierarchy,fcvFindContoursAllocate(width)); fcvDrawContouru8(dst,width,height,width,30,holeflag,pNumContourPoints,pContourStartPointsdraw,30,pPointBuffer,hierarchy,12,2,125,125); //convert to arbg 32 bit for (int i=0; i < bufferin->Length;i++){ uint8_t y = *dst++; bufferout[i] = (0xFF <<24) + (y <<16) + (y <<8) + y; }
Hi,
Your code for memory allocation is incorrect. For example, sizeof(*pPointBuffer) is 4. After you specify maximum number of contours to search for (30 in your example), you need to allocate reasonable amount of momory for the contour point coordinates, as well as other buffers.
Hope this helps.
Cheers,
-Jeff
Thanks jeff, but it still have problem
I added more amount of memory, now it compile and run with no error, but there's no contour drawn in screen, just black screen.
this is the snapshoot
I changed the code to
Ah its all works, forgot to change pointbufferSize parameter, thanks!
I am experiencing a similar problem. I can succesfully use findcontoursexternal8u without any errors. I guess, I could allocate the pointers properly. However, I cannot edit the code to use the findcontourstree8u function. The only extra parameter is holeflag which I also allocated enough memory. When, I try to use tree version instead of extenral version, the code breaks immediately. I couldnt look debug the code exactly, but I think it is different from the problems related to pointer issues. I say so , because when I made mistakes for external contours using pointerw, the application exited with acces violation, now that it exists with error code 1 and just that.
I hope someone could help me with this.