Ask Your Question

(OpenCv Java) FaceMark: Exception: bad allocation during using FaceMark for loadModel

asked 2018-10-20 03:05:21 -0500

jayaise gravatar image

updated 2018-10-20 03:20:50 -0500

berak gravatar image

// detect faces Hi I am facing exception when I trying to load FaceLandMark Model using loadModel, Can you please help here,


    cascade.detectMultiScale(img, faces);
    // setup landmarks detector
    Facemark fm = Face.createFacemarkKazemi();

Exceptions as below:

Exception in thread "main" java.lang.Exception: std::exception: bad allocation
at org.opencv.face.Facemark.loadModel_0(Native Method)
at org.opencv.face.Facemark.loadModel(
at opencv3433.FaceLandMark1.main(
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-10-20 03:21:37 -0500

berak gravatar image

updated 2018-10-20 03:34:53 -0500

bad allocation means: you're out of memory ! (huge model, ~97mb)

  • watch your resources in the Task-manager
  • try to assign more memory to your java process (-Xmx)
  • check, if you built 32bit opencv libs (4gb limit), if so, try with 64bit
  • the LBF model is only half the size (and also more precise, imho)
edit flag offensive delete link more


I made Java vm args to 2056 in eclipse but still no luck.

Code changed to createFacemarkLBF() :

    Facemark fm = Face.createFacemarkLBF();//.createFacemarkKazemi();

Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: OpenCV(3.4.3) C:\opencv343\opencv-3.4.3\modules\core\src\persistence_c.cpp:388: error: (-49:Unknown error code -49) Input file is empty in function 'cvOpenFileStorage'

at org.opencv.face.Facemark.loadModel_0(Native Method)
at org.opencv.face.Facemark.loadModel(
at opencv3433.FaceLandMark1.main(

loading data from : C:\Users\Jayashree\Desktop\Faces_Oct18th\model\flandmark_model.dat
jayaise gravatar imagejayaise ( 2018-10-20 05:47:29 -0500 )edit

Also where to make changes to build opencv libs to 64 bit

jayaise gravatar imagejayaise ( 2018-10-20 05:48:20 -0500 )edit

you need another model for lbf:

berak gravatar imageberak ( 2018-10-20 06:21:42 -0500 )edit

Thanks this helped

jayaise gravatar imagejayaise ( 2018-10-20 06:56:02 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-10-20 03:05:21 -0500

Seen: 111 times

Last updated: Oct 20 '18