4337e35e26c64f2825afb4c65672317964f05548
[platform/upstream/opencv.git] / samples / c / convert_cascade.c
1 #include "opencv2/objdetect/objdetect_c.h"
2 #include "opencv2/highgui/highgui_c.h"
3
4 #include <ctype.h>
5 #include <stdio.h>
6
7 static void help(void)
8 {
9     printf("\n This sample demonstrates cascade's convertation \n"
10     "Usage:\n"
11     "./convert_cascade --size=\"<width>x<height>\"<convertation size> \n"
12     "                   input_cascade_path \n"
13     "                   output_cascade_filename\n"
14     "Example: \n"
15     "./convert_cascade --size=640x480 ../../opencv/data/haarcascades/haarcascade_eye.xml ../../opencv/data/haarcascades/test_cascade.xml \n"
16     );
17 }
18
19 int main( int argc, char** argv )
20 {
21     const char* size_opt = "--size=";
22     char comment[1024];
23     CvHaarClassifierCascade* cascade = 0;
24     CvSize size;
25
26     help();
27
28     if( argc != 4 || strncmp( argv[1], size_opt, strlen(size_opt) ) != 0 )
29     {
30         help();
31         return -1;
32     }
33
34     sscanf( argv[1], "--size=%ux%u", &size.width, &size.height );
35     cascade = cvLoadHaarClassifierCascade( argv[2], size );
36
37     if( !cascade )
38     {
39         fprintf( stderr, "Input cascade could not be found/opened\n" );
40         return -1;
41     }
42
43     sprintf( comment, "Automatically converted from %s, window size = %dx%d", argv[2], size.width, size.height );
44     cvSave( argv[3], cascade, 0, comment, cvAttrList(0,0) );
45     return 0;
46 }
47
48 #ifdef _EiC
49 main(1,"facedetect.c");
50 #endif