Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

Problem with IppiHaarClassifier


I have some questions with regard to the IppiHaarClassifier.

First the manual says that during the intial allocation all pFeature, pWeight, pVal1, pVal2, and pThreshold should be vectors of length sum_(i=0:length-1) pNum, although according to the formula on page 14-55 (Ipp5.0) only pFeature and pWeight should be of that length, while the others should have length entries. Is this correct? Also, according the manual the IppiHaarClassifierInitAlloc should return an error if length != sum_(i=0:length-1) pNum, but this equality does not make sense and also is not enforced.

My second question is with regard to the number of features that each classifier can be made up of. In the manual there is no mention of a limit, but I noticed some weird behavior. If use a single classifier, and I use the same feature more then 4 times (pNum[0] > 4), then I get a memory access error inside the ippApplyHaarClassifier function ("memory cannot be written",for both 32f and 32s32f varieties).

If I know increase the number of classifiers to 2, then EACH classifier can suddenly use an arbitrary number of classifiers without causing the problem. I have attached my code below (changing the variable noClassifiers from 2 to 1 will make the memory error appear.

Thanks for any suggestions,


/* classifier declarations */

IppiHaarClassifier_32f *pClassifier = 0;

int ii, jj,cnt, *pNumWindowsPerClassifier, noClassifiers;

int numWindows, numPositive = 0;

IppiRect *pFeature;

Ipp32f *pWeight, *pThreshold, *pVal1, *pVal2, stageThreshold;

IppStatus errCode;

IppiSize ippSize;

/* image and integral image declarations */

IppiSize imSize = {320,240};

Ipp8u *pSrcImg, *pMaskImg;

Ipp32f *pNormImg, *pIntImg;

int srcStride, maskStride, normStride, intStride;

/* create source image */

pSrcImg = ippiMalloc_8u_C1(imSize.width, imSize.height, &srcStride);

errCode = ippiSet_8u_C1R(1,pSrcImg,srcStride,imSize);

/* create integral image */

pIntImg = ippiMalloc_32f_C1(imSize.width+1, imSize.height+1, &intStride);

errCode = ippiIntegral_8u32f_C1R(pSrcImg, srcStride,

pIntImg, intStride, imSize,0);

/* create mask image */

pMaskImg = ippiMalloc_8u_C1(imSize.width, imSize.height, &maskStride);

errCode = ippiSet_8u_C1R(1,pMaskImg,maskStride,imSize);

/* create norm image */

pNormImg = ippiMalloc_32f_C1(imSize.width, imSize.height, &normStride);

errCode = ippiSet_32f_C1R(1.0f,pNormImg,normStride,imSize);

/* create classifier structure */

noClassifiers = 2;

pNumWindowsPerClassifier = ippsMalloc_32s(noClassifiers);

numWindows = 0;

for (ii = 0; ii noClassifiers; ii++){

pNumWindowsPerClassifier[ii] = 256;

numWindows += pNumWindowsPerClassifier[ii];


/* allocate structures */

pFeature = (IppiRect*) ippsMalloc_8u(numWindows*sizeof(IppiRect));

pWeight = ippsMalloc_32f(numWindows);

pThreshold = ippsMalloc_32f(noClassifiers);

pVal1 = ippsMalloc_32f(noClassifiers);

pVal2 = ippsMalloc_32f(noClassifiers);

/* fill classifier struct */

cnt = 0;

for (ii = 0; ii noClassifiers; ii++){

for (jj = 0; jj pNumWindowsPerClassifier[ii]; jj++){
pFeature[cnt].x = 3;

pFeature[cnt].y = 3;

pFeature[cnt].width = 2;

pFeature[cnt].height = 2;

pWeight[cnt] = 1.0f;



pThreshold[ii] = 1.0f;

pVal1[ii] = -1.0f;

pVal2[ii] = 1.0f;


stageThreshold = 0.0f;

errCode = ippiHaarClassifierInitAlloc_32f(


pNumWindowsPerClassifier, noClassifiers);

ippSize.height = 120;

ippSize.width = 300;

numPositive = ippSize.height*ippSize.width;

errCode = ippiApplyHaarClassifier_32f_C1R(

pIntImg, intStride,

pNormImg, normStride,

pMaskImg, maskStride,

ippSize, &numPositive, stageThreshold, pClassifier);

errCode = ippiHaarClassifierFree_32f(pClassifier);










0 Kudos
3 Replies

Good day.

Thank you for the questions.

About first. There is a mistake in the manual. It will be improved.

About second. Iran your code but didn't get memory access error . Please, sendthe whole project with initial data to identify the problem.

P.S. Probably problem is in syntactic errors of your code - in loop names.

Yours faithfully, Alexander Turovets
0 Kudos
Hi Alexander,

thanks a lot for taking a look at my code. I put the code into its own VS Studio 2003 .NET project, and added command line input of the number of classifiers and number of windows per classifier.

When I run it in the debugger, I am getting unhandled exceptions inside the ippiApplyClassifier_32s32f call on my Intel Centrino laptop. Here is the output from VS studio (I pressed continue to continue execution after the breakpoints):

'IppHaarClassifierTest.exe': Loaded 'C:homeSRCPedestrianIppHaarClassifierTestDebugIppHaarClassifierTest.exe', Symbols loaded.
'IppHaarClassifierTest.exe': Loaded 'C:WINDOWSsystem32 tdll.dll', No symbols loaded.
'IppHaarClassifierTest.exe': Loaded 'C:WINDOWSsystem32kernel32.dll', No symbols loaded.
'IppHaarClassifierTest.exe': Loaded 'C:Program FilesIntelIPP5.0ia32inipps.dll', No symbols loaded.
'IppHaarClassifierTest.exe': Loaded 'C:Program FilesIntelIPP5.0ia32inippcore.dll', No symbols loaded.
'IppHaarClassifierTest.exe': Loaded 'C:WINDOWSsystem32libguide40.dll', No symbols loaded.
'IppHaarClassifierTest.exe': Loaded 'C:WINDOWSsystem32user32.dll', No symbols loaded.
'IppHaarClassifierTest.exe': Loaded 'C:WINDOWSsystem32gdi32.dll', No symbols loaded.
'IppHaarClassifierTest.exe': Loaded 'C:WINDOWSsystem32advapi32.dll', No symbols loaded.
'IppHaarClassifierTest.exe': Loaded 'C:WINDOWSsystem32 pcrt4.dll', No symbols loaded.
'IppHaarClassifierTest.exe': Loaded 'C:Program FilesIntelIPP5.0ia32inippi.dll', No symbols loaded.
'IppHaarClassifierTest.exe': Loaded 'C:Program FilesIntelIPP5.0ia32inippcv.dll', No symbols loaded.
'IppHaarClassifierTest.exe': Loaded 'C:Program FilesGoogleGoogle Desktop SearchGoogleDesktopNetwork3.dll', No symbols loaded.
'IppHaarClassifierTest.exe': Loaded 'C:WINDOWSsystem32ws2_32.dll', No symbols loaded.
'IppHaarClassifierTest.exe': Loaded 'C:WINDOWSsystem32msvcrt.dll', No symbols loaded.
'IppHaarClassifierTest.exe': Loaded 'C:WINDOWSsystem32ws2help.dll', No symbols loaded.
'IppHaarClassifierTest.exe': Unloaded 'C:Program FilesGoogleGoogle Desktop SearchGoogleDesktopNetwork3.dll'
'IppHaarClassifierTest.exe': Unloaded 'C:WINDOWSsystem32ws2_32.dll'
'IppHaarClassifierTest.exe': Unloaded 'C:WINDOWSsystem32ws2help.dll'
'IppHaarClassifierTest.exe': Unloaded 'C:WINDOWSsystem32msvcrt.dll'
'IppHaarClassifierTest.exe': Loaded 'C:Program FilesIntelIPP5.0ia32inippsw7.dll', No symbols loaded.
'IppHaarClassifierTest.exe': Loaded 'C:Program FilesIntelIPP5.0ia32inippiw7.dll', No symbols loaded.
'IppHaarClassifierTest.exe': Loaded 'C:Program FilesIntelIPP5.0ia32inippcvw7.dll', No symbols loaded.
HEAP[IppHaarClassifierTest.exe]: Heap block at 011B58F0 modified at 011B594C past requested size of 54
Unhandled exception at 0x7c901230 in IppHaarClassifierTest.exe: User breakpoint.
HEAP[IppHaarClassifierTest.exe]: Invalid Address specified to RtlFreeHeap( 011B0000, 011B58F8 )
Unhandled exception at 0x7c901230 in IppHaarClassifierTest.exe: User breakpoint.
Heap corruption detected at 011B28C8
First-chance exception at 0x7c926a36 in IppHaarClassifierTest.exe:
0xC0000005: Access violation writing location 0x000003db.
First-chance exception at 0x7c911e58 in IppHaarClassifierTest.exe: 0xC0000005: Access violation reading location 0x000003db.
The program '[984] IppHaarClassifierTest.exe: Native' has exited with code 0 (0x0).

When I run the executable in cygwin with 1 classifier and n windows for this classifier, I get a different access error when before if n is larger then 59. If use 2 classifiers, then the sum of the lengths of both classifiers hast to be less then 58, to run without an access error.

I attached my project. BTW, I am using IPP 5.0.

Thanks a lot,

0 Kudos
Good day, Jan
ippiApplyHaarClassifier_32f_C1R and ippiApplyHaarClassifier_32s32f_C1R work correctly for classifiers with not more than 3 features
Thismistake corrected in Ipp5.1
Yours faithfully, Alexander Turovets
0 Kudos