Added error handling in latentsvmdetect sample

This commit is contained in:
Alexey Polovinkin
2010-10-16 07:10:46 +00:00
parent f678c8f07b
commit ba88b2ee54
5 changed files with 28 additions and 6 deletions

View File

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 64 KiB

View File

@@ -6,7 +6,7 @@
using namespace cv;
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)
{
@@ -35,8 +35,26 @@ void detect_and_draw_objects( IplImage* image, CvLatentSvmDetector* detector)
int main(int argc, char* argv[])
{
if (argc > 2)
{
image_filename = argv[1];
model_filename = argv[2];
}
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);
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 );
cvNamedWindow( "test", 0 );
cvShowImage( "test", image );