Forums - Help Using fcvFindContour

5 posts / 0 new
Last post
Help Using fcvFindContour
dnca
Join Date: 7 Jul 13
Posts: 3
Posted: Thu, 2013-10-03 08:21

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;
}
 

 

  • Up0
  • Down0
jeff4s Moderator
Join Date: 4 Nov 12
Posts: 106
Posted: Tue, 2013-10-08 16:36

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

  • Up0
  • Down0
dnca
Join Date: 7 Jul 13
Posts: 3
Posted: Wed, 2013-10-09 05:18

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
 

		//convert to binary image
		fcvAdaptiveThresholdGaussian5x5u8(src,width,height,width,255,FCV_THRESH_BINARY,4,dst,width);
		//declaration variable to fill fcvFindContours parameters
		uint32_t maxNumContours = 300;
		uint32_t maxPoints= ((2*width) + (2 * height));
		uint32_t * pNumContours=(uint32_t *)malloc(maxNumContours * sizeof(*pNumContours));
		uint32_t * pNumContourPoints=(uint32_t *)malloc( maxPoints * sizeof(*pNumContourPoints));
		uint32_t **__restrict pContourStartPointsfind=(uint32_t **)malloc(maxPoints*2* sizeof(*pContourStartPointsfind));
		const uint32_t **__restrict pContourStartPointsdraw =(const uint32_t **__restrict)malloc(maxPoints * 2* sizeof(**pContourStartPointsdraw)) ;
		uint32_t * pPointBuffer=(uint32_t *)malloc(maxPoints * sizeof(*pPointBuffer));
		int32_t hierarchy[30][4];
		uint32_t * holeflag = (uint32_t *)malloc(maxNumContours * sizeof(*holeflag));
		fcvFindContoursExternalu8(dst,width,height,width,maxNumContours,pNumContours,pNumContourPoints,pContourStartPointsfind,pPointBuffer,30,hierarchy,fcvFindContoursAllocate(width));
		pContourStartPointsdraw = (const uint32_t **__restrict)pContourStartPointsfind;
		fcvDrawContouru8(dst,width,height,width,maxNumContours,holeflag,pNumContourPoints,pContourStartPointsdraw, maxPoints,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;
		}

 

  • Up0
  • Down0
dnca
Join Date: 7 Jul 13
Posts: 3
Posted: Wed, 2013-10-09 18:19

Ah its all works, forgot to change pointbufferSize parameter, thanks!

  • Up0
  • Down0
bahti_lep
Join Date: 29 Dec 13
Posts: 3
Posted: Thu, 2014-01-02 16:02

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. 

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.