Ask Your Question

OpenCV traincascade fails: Insufficient memory

asked 2014-02-05 04:22:18 -0600

Adi Ulici gravatar image


I'm trying to use the traincascade app to create my own data, but it keeps giving me insufficient memory even though I have enough free memory.

OpenCV Error: Insufficient memory (Failed to allocate 536871664 bytes) in unknown function, file D:\Dev\opencv\modules\core\src\alloc.cpp, line 52

My samples file has 1000 positive samples of size 50x50. I tried with 500 also, it didn't work. Only with 100 worked but I'm afraid that isn't enough.

edit retag flag offensive close merge delete


Actually, can you specify your full command. It takes standard only 256 MB of memory for calculation. Have your tried increasing that parameter to for example 2047 MB?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-02-05 09:13:06 -0600 )edit

This is the command I'm using: opencv_traincascaded -data ./trained5/ -vec samples.vec -bg neg.txt -numPos 300 -numNeg 7 -w 50 -h 50 -numStages 5

Adi Ulici gravatar imageAdi Ulici ( 2014-02-05 09:49:23 -0600 )edit

I tried using precalcValBufSize and precalcIdxBufSize to increase the buffer size to 2048 but it gives me the same error..

Adi Ulici gravatar imageAdi Ulici ( 2014-02-05 09:54:18 -0600 )edit

Two more questions: what is the size of your negatives and how much free memory do you have? I personally met with this kind of problem and the solution was that I had to close some of my applications (in spite of my 4 GB total memory).

Ps.: Sometimes the traincascade can consume at least 1 GB.

Bartis Áron gravatar imageBartis Áron ( 2014-02-05 13:24:02 -0600 )edit

I have cascade training processes grabbing up to 3GB of memory, so it is surely not even limited to 1GB. However the amount of training samples are sufficiently larger in that case...

StevenPuttemans gravatar imageStevenPuttemans ( 2014-02-06 03:59:57 -0600 )edit

1 answer

Sort by » oldest newest most voted

answered 2014-02-05 10:34:27 -0600

Instead of your command try this:

1)opencv_traincascade -data ./trained5/ -vec samples.vec -bg neg.txt -numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 300 -numNeg 7 -w 50 -h 50 -mode ALL -precalcValBufSize 1024 -precalcIdxBufSize 1024


2)opencv_traincascade -data classifier -vec samples.vec -bg negatives.txt\ -numStages 20 -minHitRate 0.999 -maxFalseAlarmRate 0.5 -numPos 1000\ -numNeg 600 -w 80 -h 40 -mode ALL -precalcValBufSize 1024\ -precalcIdxBufSize 1024 -nonsym -mem 512 -mode ALL

(NOTE :-use opencv_traincascaded if the .exe file in the bin is opencv_traincascaded)

Hope this helps you :)

edit flag offensive delete link more


Hi Abhishek, i am trying to create traincasade.exe but it is throwing Debug Assertion Failed! in msvisualstudio \xString line :1143 expression :invalid null pointer . and can you tell me which version of opencv are using ?? and what is the size of .exe ???

ART gravatar imageART ( 2014-02-19 00:57:17 -0600 )edit

See I am using opencv- in ubuntu 12.04,so,the traincascade.exe you are talking about is opencv_traincascade.exe i created when i installed opencv.Its size is 300.5 kB.Since u r trying to compile traincascade.cpp,make sure u include all the required libraries,even the header files require a lot of libraries to be present in the compilation folder.Other way round you can make use of make file present in the traincascade folder in opencv download directory to compile.Again once you use the make file to compile it will create a opencv_traincascade.exe in the build/bin directory.

Hope this helps you :)

Abhishek Kumar Annamraju gravatar imageAbhishek Kumar Annamraju ( 2014-02-19 02:12:17 -0600 )edit

Question Tools


Asked: 2014-02-05 04:22:18 -0600

Seen: 6,984 times

Last updated: Feb 05 '14