Added error handling in latentsvmdetect sample
authorAlexey Polovinkin <no@email>
Sat, 16 Oct 2010 07:10:46 +0000 (07:10 +0000)
committerAlexey Polovinkin <no@email>
Sat, 16 Oct 2010 07:10:46 +0000 (07:10 +0000)
modules/objdetect/src/_lsvm_error.h
modules/objdetect/src/latentsvmdetector.cpp
modules/objdetect/src/lsvmparser.cpp
samples/c/cat.jpg [moved from samples/c/000028.jpg with 100% similarity]
samples/c/latentsvmdetect.cpp

index 7de5448..1d6fb63 100644 (file)
@@ -12,5 +12,6 @@
 #define FILTER_OUT_OF_BOUNDARIES -7
 #define FFT_OK 2
 #define FFT_ERROR -8
+#define LSVM_PARSER_FILE_NOT_FOUND -9
 
 #endif
index add81ac..336a360 100644 (file)
@@ -22,8 +22,10 @@ CvLatentSvmDetector* cvLoadLatentSvmDetector(const char* filename)
        int* kPartFilters = 0;\r
        float* b = 0;\r
        float scoreThreshold = 0.f;\r
+       int err_code = 0;\r
 \r
-       loadModel(filename, &filters, &kFilters, &kComponents, &kPartFilters, &b, &scoreThreshold);\r
+       err_code = loadModel(filename, &filters, &kFilters, &kComponents, &kPartFilters, &b, &scoreThreshold);\r
+       if (err_code != LATENT_SVM_OK) return 0;\r
 \r
        detector = (CvLatentSvmDetector*)malloc(sizeof(CvLatentSvmDetector));\r
        detector->filters = filters;\r
index 72b9dcb..a87416f 100644 (file)
@@ -2,6 +2,7 @@
 #include <stdio.h>\r
 #include "string.h"\r
 #include "_lsvmparser.h"\r
+#include "_lsvm_error.h"\r
 \r
 int isMODEL    (char *str){\r
     char stag [] = "<Model>";\r
@@ -736,7 +737,7 @@ int LSVMparser(const char * filename, filterObject *** model, int *last, int *ma
 \r
     xmlf = fopen(filename, "rb");\r
        if(xmlf == NULL){\r
-               return -1;\r
+               return LSVM_PARSER_FILE_NOT_FOUND;\r
        }\r
     \r
     i   = 0;\r
@@ -767,7 +768,7 @@ int LSVMparser(const char * filename, filterObject *** model, int *last, int *ma
             }\r
         }        \r
     }\r
-       return 0;\r
+       return LATENT_SVM_OK;\r
 }\r
 \r
 int loadModel(\r
@@ -789,8 +790,8 @@ int loadModel(
     //printf("start_parse\n\n");\r
 \r
     err = LSVMparser(modelPath, filters, &last, &max, &comp, b, &count, &score);\r
-       if(err != 0){\r
-               return -1;\r
+       if(err != LATENT_SVM_OK){\r
+               return err;\r
        }\r
     (*kFilters)       = last + 1;\r
     (*kComponents)    = count;\r
similarity index 100%
rename from samples/c/000028.jpg
rename to samples/c/cat.jpg
index 76c9840..b683d93 100644 (file)
@@ -6,7 +6,7 @@
 using namespace cv;\r
 \r
 const char* model_filename = "cat.xml";\r
-const char* image_filename = "000028.jpg";\r
+const char* image_filename = "cat.jpg";\r
 \r
 void detect_and_draw_objects( IplImage* image, CvLatentSvmDetector* detector)\r
 {\r
@@ -35,8 +35,26 @@ void detect_and_draw_objects( IplImage* image, CvLatentSvmDetector* detector)
 \r
 int main(int argc, char* argv[])\r
 {\r
+       if (argc > 2)\r
+       {\r
+               image_filename = argv[1];\r
+               model_filename = argv[2];\r
+       }\r
        IplImage* image = cvLoadImage(image_filename);\r
+       if (!image)\r
+       {\r
+               printf( "Unable to load the image\n"
+                "Pass it as the first parameter: latentsvmdetect <path to cat.jpg> <path to cat.xml>\n" );\r
+               return -1;\r
+       }\r
     CvLatentSvmDetector* detector = cvLoadLatentSvmDetector(model_filename);\r
+       if (!detector)\r
+       {\r
+               printf( "Unable to load the model\n"
+                "Pass it as the second parameter: latentsvmdetect <path to cat.jpg> <path to cat.xml>\n" );\r
+               cvReleaseImage( &image );\r
+               return -1;\r
+       }\r
     detect_and_draw_objects( image, detector );\r
     cvNamedWindow( "test", 0 );\r
     cvShowImage( "test", image );\r