Forums - Problems with fcvDrawContouru8

2 posts / 0 new
Last post
Problems with fcvDrawContouru8
SerPodrick
Join Date: 26 Nov 15
Posts: 1
Posted: Thu, 2015-11-26 02:08

Hello,

I am using fastcv v1.7 to develop an image processing algorithm, a part of the process includes finding conturs from an image, selecting a choice few contours among them and then drawing those contours only.

This code block runs smoothly in 32bit systems producing expected output but while on 64bit systems same code crashes unexpectedly during the loop which executes fcvDrawContouru8. The crash is unexpected as sometimes loop iterataes 2 or 3 times and sometimes crashes on first iteration. Can't seem to work out if the problem is with memory allocation in 64bit or with fastcv itself. Any suggestions will be helpful.
 

The error shown is:

01-18 11:05:41.342: A/libc(17295): Fatal signal 11 (SIGSEGV), code 1, fault addr 0x50 in tid 17726 (AsyncTask #1)

 
uint8_t* dist_fcv = (uint8_t*)fcvMemAlloc(dist_8u.cols*dist_8u.rows*OPT_CV_ELEM_SIZE(OPT_CV_8UC1), FCV_ALIGN);
memset(dist_fcv, 0, dist_8u.cols*dist_8u.rows*OPT_CV_ELEM_SIZE(OPT_CV_8UC1));
 
uint32_t maxNumContours = MAX_CNT;
uint32_t sizeOfpBuffer = 0;
uint32_t maxPoints= ((2*dist_8u.cols) + (2 * dist_8u.rows));
uint32_t  pNumContours = 0;
uint32_t pNumContourPoints[MAX_CNT] = {0};
uint32_t** pContourStartPointsfind = (uint32_t**)fcvMemAlloc(MAX_CNT*2*sizeof(uint32_t*),16);
sizeOfpBuffer = (MAX_CNT * 2 * maxPoints * sizeof(uint32_t));
uint32_t *pPointBuffer=(uint32_t *)malloc(sizeOfpBuffer);
memset(pPointBuffer,0,sizeOfpBuffer);
int32_t hierarchy[MAX_CNT][4];
void* cHandle = fcvFindContoursAllocate(dist_8u.cols);
 
fcvFindContoursExternalu8(textureless.data.ptr,
dist_8u.cols,
dist_8u.rows,
dist_8u.cols,
maxNumContours,
&pNumContours,
pNumContourPoints,
pContourStartPointsfind,
pPointBuffer,
sizeOfpBuffer,
hierarchy,
cHandle);
 
size_t n_TL = 0;
 
uint32_t** pContourStartPointsdraw = (uint32_t**)fcvMemAlloc(MAX_CNT*2*sizeof(uint32_t*),16);
uint32_t pNumDrawContourPoints[MAX_CNT] = {0};
uint32_t* dPointBuffer=(uint32_t *)malloc(sizeOfpBuffer);
uint32_t* start_contour = pPointBuffer;
uint32_t* start_contour_dPoint = dPointBuffer;
 
uint32_t** startFind_ptr = pContourStartPointsfind;
uint32_t** draw_ptr = pContourStartPointsdraw;
 
for (size_t i = 0; i < pNumContours; i++,startFind_ptr++)
{
 
int points_per_contour = pNumContourPoints[i];
double area = polyArea(start_contour,points_per_contour*2);
 
if(area < min_textureless_area)
{
start_contour = start_contour + points_per_contour*2;
continue;
}
 
*(draw_ptr) = *(startFind_ptr);
pNumDrawContourPoints[n_TL] = pNumContourPoints[i];
memcpy(start_contour_dPoint,start_contour,points_per_contour*2*sizeof(uint32_t));
start_contour_dPoint = start_contour_dPoint + points_per_contour*2;
start_contour = start_contour + points_per_contour*2;
n_TL++;
draw_ptr++;
 
 
}
 
uint32_t* holeflag = (uint32_t*)malloc(pNumContours*sizeof(uint32_t));
memset(holeflag,0,pNumContours*sizeof(uint32_t));
uint32_t bufferSize = 0;
 
start_contour_dPoint = dPointBuffer;
 
draw_ptr = pContourStartPointsdraw;
 
for(int i = 0; i < n_TL; i++)
{
int points_per_contour = pNumDrawContourPoints[i];
bufferSize = points_per_contour*2*sizeof(uint32_t);
 
fcvDrawContouru8(dist_fcv,
dist_8u.cols,
dist_8u.rows,
dist_8u.cols,
1,
holeflag,
&pNumDrawContourPoints[i],
(const uint32_t ** __restrict)(draw_ptr),
bufferSize,
start_contour_dPoint,
hierarchy,
1,1,i+1,0)
 
start_contour_dPoint = start_contour_dPoint + points_per_contour*2;
draw_ptr++;
 
 
}
 
free(pPointBuffer);
fcvFindContoursDelete(cHandle);
fcvMemFree(pContourStartPointsfind);
 
  • Up0
  • Down0
krishanu6690
Join Date: 24 Nov 13
Posts: 10
Posted: Mon, 2015-11-30 00:18

Hi, 

   A few things that I have noted in the following statements in your code :

   sizeOfpBuffer = (MAX_CNT * 2 * maxPoints * sizeof(uint32_t));
   memcpy(start_contour_dPoint,start_contour,points_per_contour*2*sizeof(uint32_t)); 
   uint32_t* holeflag = (uint32_t*)malloc(pNumContours*sizeof(uint32_t));
   bufferSize = points_per_contour*2*sizeof(uint32_t);
 
I will suggest you to use sizeof(uintptr_t) instead of sizeof(uint32_t). The reason being the size of uint32_t is different on 32-bit and 64-bit architectures. Using uintptr_t will alocate memory correspoding to the architectures. Can you please try this and let me know if this fixes the crashes for you. Please make the corresponding changes in other segments of the code as per requirement
  • 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.