Added error handling in latentsvmdetect sample
This commit is contained in:
parent
f678c8f07b
commit
ba88b2ee54
@ -12,5 +12,6 @@
|
|||||||
#define FILTER_OUT_OF_BOUNDARIES -7
|
#define FILTER_OUT_OF_BOUNDARIES -7
|
||||||
#define FFT_OK 2
|
#define FFT_OK 2
|
||||||
#define FFT_ERROR -8
|
#define FFT_ERROR -8
|
||||||
|
#define LSVM_PARSER_FILE_NOT_FOUND -9
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -22,8 +22,10 @@ CvLatentSvmDetector* cvLoadLatentSvmDetector(const char* filename)
|
|||||||
int* kPartFilters = 0;
|
int* kPartFilters = 0;
|
||||||
float* b = 0;
|
float* b = 0;
|
||||||
float scoreThreshold = 0.f;
|
float scoreThreshold = 0.f;
|
||||||
|
int err_code = 0;
|
||||||
|
|
||||||
loadModel(filename, &filters, &kFilters, &kComponents, &kPartFilters, &b, &scoreThreshold);
|
err_code = loadModel(filename, &filters, &kFilters, &kComponents, &kPartFilters, &b, &scoreThreshold);
|
||||||
|
if (err_code != LATENT_SVM_OK) return 0;
|
||||||
|
|
||||||
detector = (CvLatentSvmDetector*)malloc(sizeof(CvLatentSvmDetector));
|
detector = (CvLatentSvmDetector*)malloc(sizeof(CvLatentSvmDetector));
|
||||||
detector->filters = filters;
|
detector->filters = filters;
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "_lsvmparser.h"
|
#include "_lsvmparser.h"
|
||||||
|
#include "_lsvm_error.h"
|
||||||
|
|
||||||
int isMODEL (char *str){
|
int isMODEL (char *str){
|
||||||
char stag [] = "<Model>";
|
char stag [] = "<Model>";
|
||||||
@ -736,7 +737,7 @@ int LSVMparser(const char * filename, filterObject *** model, int *last, int *ma
|
|||||||
|
|
||||||
xmlf = fopen(filename, "rb");
|
xmlf = fopen(filename, "rb");
|
||||||
if(xmlf == NULL){
|
if(xmlf == NULL){
|
||||||
return -1;
|
return LSVM_PARSER_FILE_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
@ -767,7 +768,7 @@ int LSVMparser(const char * filename, filterObject *** model, int *last, int *ma
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return LATENT_SVM_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
int loadModel(
|
int loadModel(
|
||||||
@ -789,8 +790,8 @@ int loadModel(
|
|||||||
//printf("start_parse\n\n");
|
//printf("start_parse\n\n");
|
||||||
|
|
||||||
err = LSVMparser(modelPath, filters, &last, &max, &comp, b, &count, &score);
|
err = LSVMparser(modelPath, filters, &last, &max, &comp, b, &count, &score);
|
||||||
if(err != 0){
|
if(err != LATENT_SVM_OK){
|
||||||
return -1;
|
return err;
|
||||||
}
|
}
|
||||||
(*kFilters) = last + 1;
|
(*kFilters) = last + 1;
|
||||||
(*kComponents) = count;
|
(*kComponents) = count;
|
||||||
|
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 64 KiB |
@ -6,7 +6,7 @@
|
|||||||
using namespace cv;
|
using namespace cv;
|
||||||
|
|
||||||
const char* model_filename = "cat.xml";
|
const char* model_filename = "cat.xml";
|
||||||
const char* image_filename = "000028.jpg";
|
const char* image_filename = "cat.jpg";
|
||||||
|
|
||||||
void detect_and_draw_objects( IplImage* image, CvLatentSvmDetector* detector)
|
void detect_and_draw_objects( IplImage* image, CvLatentSvmDetector* detector)
|
||||||
{
|
{
|
||||||
@ -35,8 +35,26 @@ void detect_and_draw_objects( IplImage* image, CvLatentSvmDetector* detector)
|
|||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
|
if (argc > 2)
|
||||||
|
{
|
||||||
|
image_filename = argv[1];
|
||||||
|
model_filename = argv[2];
|
||||||
|
}
|
||||||
IplImage* image = cvLoadImage(image_filename);
|
IplImage* image = cvLoadImage(image_filename);
|
||||||
|
if (!image)
|
||||||
|
{
|
||||||
|
printf( "Unable to load the image\n"
|
||||||
|
"Pass it as the first parameter: latentsvmdetect <path to cat.jpg> <path to cat.xml>\n" );
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
CvLatentSvmDetector* detector = cvLoadLatentSvmDetector(model_filename);
|
CvLatentSvmDetector* detector = cvLoadLatentSvmDetector(model_filename);
|
||||||
|
if (!detector)
|
||||||
|
{
|
||||||
|
printf( "Unable to load the model\n"
|
||||||
|
"Pass it as the second parameter: latentsvmdetect <path to cat.jpg> <path to cat.xml>\n" );
|
||||||
|
cvReleaseImage( &image );
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
detect_and_draw_objects( image, detector );
|
detect_and_draw_objects( image, detector );
|
||||||
cvNamedWindow( "test", 0 );
|
cvNamedWindow( "test", 0 );
|
||||||
cvShowImage( "test", image );
|
cvShowImage( "test", image );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user