From 110351d3de1853fc32b80ba8941434ad2af97888 Mon Sep 17 00:00:00 2001 From: Valentina Kustikova Date: Fri, 8 Apr 2011 03:51:40 +0000 Subject: [PATCH] Bugs in the test for LatentSVM were fixed. --- modules/objdetect/src/latentsvm.cpp | 13 ++++++++++- modules/objdetect/src/latentsvmdetector.cpp | 14 ++++++++---- .../objdetect/test/test_latentsvmdetector.cpp | 22 +++++++++++++++---- tests/cv/src/latentsvmdetector.cpp | 21 +++++++++++++----- 4 files changed, 56 insertions(+), 14 deletions(-) diff --git a/modules/objdetect/src/latentsvm.cpp b/modules/objdetect/src/latentsvm.cpp index c6501fa2d7..20358044a9 100644 --- a/modules/objdetect/src/latentsvm.cpp +++ b/modules/objdetect/src/latentsvm.cpp @@ -576,10 +576,21 @@ int searchObjectThresholdSomeComponents(const CvLSVMFeaturePyramid *H, for (i = 0; i < kComponents; i++) { #ifdef HAVE_TBB - searchObjectThreshold(H, &(filters[componentIndex]), kPartFilters[i], + error = searchObjectThreshold(H, &(filters[componentIndex]), kPartFilters[i], b[i], maxXBorder, maxYBorder, scoreThreshold, &(pointsArr[i]), &(levelsArr[i]), &(kPointsArr[i]), &(scoreArr[i]), &(partsDisplacementArr[i]), numThreads); + if (error != LATENT_SVM_OK) + { + // Release allocated memory + free(pointsArr); + free(oppPointsArr); + free(scoreArr); + free(kPointsArr); + free(levelsArr); + free(partsDisplacementArr); + return LATENT_SVM_SEARCH_OBJECT_FAILED; + } #else searchObjectThreshold(H, &(filters[componentIndex]), kPartFilters[i], b[i], maxXBorder, maxYBorder, scoreThreshold, diff --git a/modules/objdetect/src/latentsvmdetector.cpp b/modules/objdetect/src/latentsvmdetector.cpp index 28ebb76729..5b39e45c99 100644 --- a/modules/objdetect/src/latentsvmdetector.cpp +++ b/modules/objdetect/src/latentsvmdetector.cpp @@ -95,16 +95,22 @@ CvSeq* cvLatentSvmDetectObjects(IplImage* image, CvPoint *oppPointsOut = 0; float *scoreOut = 0; CvSeq* result_seq = 0; + int error = 0; cvConvertImage(image, image, CV_CVTIMG_SWAP_RB); // Getting maximum filter dimensions - getMaxFilterDims((const CvLSVMFilterObject**)(detector->filters), detector->num_components, detector->num_part_filters, &maxXBorder, &maxYBorder); + getMaxFilterDims((const CvLSVMFilterObject**)(detector->filters), detector->num_components, + detector->num_part_filters, &maxXBorder, &maxYBorder); // Create feature pyramid with nullable border H = createFeaturePyramidWithBorder(image, maxXBorder, maxYBorder); // Search object - searchObjectThresholdSomeComponents(H, (const CvLSVMFilterObject**)(detector->filters), detector->num_components, - detector->num_part_filters, detector->b, detector->score_threshold, - &points, &oppPoints, &score, &kPoints, numThreads); + error = searchObjectThresholdSomeComponents(H, (const CvLSVMFilterObject**)(detector->filters), + detector->num_components, detector->num_part_filters, detector->b, detector->score_threshold, + &points, &oppPoints, &score, &kPoints, numThreads); + if (error != LATENT_SVM_OK) + { + return NULL; + } // Clipping boxes clippingBoxes(image->width, image->height, points, kPoints); clippingBoxes(image->width, image->height, oppPoints, kPoints); diff --git a/modules/objdetect/test/test_latentsvmdetector.cpp b/modules/objdetect/test/test_latentsvmdetector.cpp index 0e481deada..ac85d553b5 100644 --- a/modules/objdetect/test/test_latentsvmdetector.cpp +++ b/modules/objdetect/test/test_latentsvmdetector.cpp @@ -44,6 +44,14 @@ #include +#ifdef HAVE_CONFIG_H +#include +#endif + +#ifdef HAVE_TBB +#include "tbb/task_scheduler_init.h" +#endif + using namespace cv; const int num_detections = 3; @@ -77,7 +85,12 @@ void CV_LatentSVMDetectorTest::run( int /* start_from */) { string img_path = string(ts->get_data_path()) + "latentsvmdetector/cat.jpg"; string model_path = string(ts->get_data_path()) + "latentsvmdetector/cat.xml"; - + int numThreads = -1; +#ifdef HAVE_TBB + numThreads = 2; + tbb::task_scheduler_init init(tbb::task_scheduler_init::deferred); + init.initialize(numThreads); +#endif IplImage* image = cvLoadImage(img_path.c_str()); if (!image) { @@ -95,8 +108,7 @@ void CV_LatentSVMDetectorTest::run( int /* start_from */) CvMemStorage* storage = cvCreateMemStorage(0); CvSeq* detections = 0; - detections = cvLatentSvmDetectObjects(image, detector, storage); - + detections = cvLatentSvmDetectObjects(image, detector, storage, 0.5f, numThreads); if (detections->total != num_detections) { ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH ); @@ -116,7 +128,9 @@ void CV_LatentSVMDetectorTest::run( int /* start_from */) } } } - +#ifdef HAVE_TBB + init.terminate(); +#endif cvReleaseMemStorage( &storage ); cvReleaseLatentSvmDetector( &detector ); cvReleaseImage( &image ); diff --git a/tests/cv/src/latentsvmdetector.cpp b/tests/cv/src/latentsvmdetector.cpp index 886c1adc31..b3748894af 100644 --- a/tests/cv/src/latentsvmdetector.cpp +++ b/tests/cv/src/latentsvmdetector.cpp @@ -43,6 +43,10 @@ #include "cvtest.h" #include +#ifdef HAVE_TBB +#include "tbb/task_scheduler_init.h" +#endif + using namespace cv; const int num_detections = 3; @@ -75,27 +79,31 @@ bool CV_LatentSVMDetectorTest::isEqual(CvRect r1, CvRect r2) void CV_LatentSVMDetectorTest::run( int /* start_from */) { - string img_path = string(ts->get_data_path()) + "latentsvmdetector/cat.jpg"; - string model_path = string(ts->get_data_path()) + "latentsvmdetector/cat.xml"; + int numThreads = -1; +#ifdef HAVE_TBB + numThreads = 2; + tbb::task_scheduler_init init(tbb::task_scheduler_init::deferred); + init.initialize(numThreads); +#endif IplImage* image = cvLoadImage(img_path.c_str()); if (!image) { - ts->set_failed_test_info( CvTS::FAIL_INVALID_TEST_DATA ); + ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); return; } CvLatentSvmDetector* detector = cvLoadLatentSvmDetector(model_path.c_str()); if (!detector) { - ts->set_failed_test_info( CvTS::FAIL_INVALID_TEST_DATA ); + ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA ); cvReleaseImage(&image); return; } CvMemStorage* storage = cvCreateMemStorage(0); CvSeq* detections = 0; - detections = cvLatentSvmDetectObjects(image, detector, storage); + detections = cvLatentSvmDetectObjects(image, detector, storage, 0.5f, numThreads); if (detections->total != num_detections) { @@ -117,6 +125,9 @@ void CV_LatentSVMDetectorTest::run( int /* start_from */) } } +#ifdef HAVE_TBB + init.terminate(); +#endif cvReleaseMemStorage( &storage ); cvReleaseLatentSvmDetector( &detector ); cvReleaseImage( &image );