Ask Your Question
0

Is there a 'c/cpp header file' alternative to OpenCV XML/YAML file storages for Real-time Object Detection in Embedded Systems, or Android NDK, etc.

asked 2015-07-04 19:04:33 -0600

I have implemented object detection in Android NDK using jni and stevehavelka's assetbridge where the cascade is loaded as follows:

Ex.

if (cat_face_cascade.empty()){
   sprintf( cat_face_cascade_path, "%s/%s", getenv("ASSETDIR"), "lbpcascade_frontalcatface.xml");     

  /* Load the face cascades */
   if( !cat_face_cascade.load(cat_face_cascade_path) ){ 
       LOGE("Error loading cat face cascade"); 
       abort(); 
   };

Full code here:

Cat-detector-Android-jni

However, I want to #include the xml cascade as a c/cpp header file to get rid of the parsing (not sure if this will help speed-up the frame rate, but i would like to try it anyway). Is there an OpenCV implementation somewhere similar to this idea?

Ex.

#ifndef CATDETECT_H
#define CATDETECT_H
/* ...
 * ...
 */

 const int HEIGHT = 24;
 const int WIDTH = 24;

 // etc.

#endif /* CATDETECT_H */
edit retag flag offensive close merge delete

Comments

1

in past, i have coded an experimental utility to convert xml cascade to a header file (for old cascades like haarcascade_frontalface_alt.xml). i can publish it if needed. but it don't help to speed up object detection

sturkmen gravatar imagesturkmen ( 2015-07-05 05:21:25 -0600 )edit
1

you can read an xml cascade from memory:

FileStorage fs( xml_as_text_string, FileStorage::READ | FileStorage::MEMORY);
classifier.read(fs.root());

but that won't give you much speedup, there's still xml to be parsed.

berak gravatar imageberak ( 2015-07-06 01:22:49 -0600 )edit

@sturkmen thank you for your insight.

mkc gravatar imagemkc ( 2015-07-06 21:59:50 -0600 )edit

@berak thanks, i will try it later.

mkc gravatar imagemkc ( 2015-07-06 22:00:46 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-07-05 04:49:46 -0600

updated 2015-08-07 02:21:25 -0600

i think you can scale down your image before detection to speed up your app as shown here

      Mat srcGray1;
      resize( srcGray, srcGray1, Size(srcGray.cols/2, srcGray.rows/2), INTER_LINEAR );
      cat_face_cascade.detectMultiScale( srcGray1, faces, 1.2, 5 , 0 , Size(64, 64));

.
.
.

for( size_t i = 0; i < faces.size(); i++ )
       {
          Point center(faces[i].x * 2 + faces[i].width, faces[i].y *2 + faces[i].height );
          ellipse(srcGray, center, Size(faces[i].width , faces[i].height ), 0, 0, 360, Scalar(255, 0, 255), 4, 8, 0);
       }//endfor

also look ufacedetect.cpp what to do --scale parameter

edit flag offensive delete link more

Comments

@sturkmen Thanks for your Answer. Indeed, it made the app much faster than before. By the way, I was playing with this last weekend and got real-time fps with multiple pyrDown(); similar to your idea of resizing the input image:

 tmp = srcGray;
 scaled = tmp;

 for (uint8_t i = 0; i < downscale; i++){
     pyrDown( tmp, scaled, Size( tmp.cols/2, tmp.rows/2 ) );
     tmp = scaled;
 }
mkc gravatar imagemkc ( 2015-07-07 00:11:55 -0600 )edit
1

hey no need multiple pyrDown(), just change divider value of resize( srcGray, srcGray1, Size(srcGray.cols/2, srcGray.rows/2), INTER_LINEAR ); like srcGray.cols/3, srcGray.cols/4 etc.

sturkmen gravatar imagesturkmen ( 2015-07-14 15:20:57 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-07-04 19:04:33 -0600

Seen: 1,054 times

Last updated: Aug 07 '15