Skip to content

Commit 3ee04c6

Browse files
author
Dinar Ahmatnurov
committed
some changes;
1 parent 05b4c7c commit 3ee04c6

File tree

5 files changed

+21
-161
lines changed

5 files changed

+21
-161
lines changed

modules/latentsvm/include/opencv2/latentsvm/latentsvm.hpp renamed to modules/latentsvm/include/opencv2/latentsvm.hpp

Lines changed: 6 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,14 @@
4343
#define __OPENCV_OBJDETECT_HPP__
4444

4545
#include "opencv2/core.hpp"
46-
#include "opencv2/core/core_c.h"
46+
//#include "opencv2/core/core_c.h"
4747

48-
#ifdef __cplusplus
4948
#include <map>
5049
#include <vector>
5150
#include <string>
52-
#endif
5351

5452
extern "C" {
5553

56-
57-
5854
/****************************************************************************************\
5955
* Latent SVM Object Detection functions *
6056
\****************************************************************************************/
@@ -63,6 +59,7 @@ extern "C" {
6359
// Structure describes the position of the filter in the feature pyramid
6460
// l - level in the feature pyramid
6561
// (x, y) - coordinate in level l
62+
6663
typedef struct CvLSVMFilterPosition
6764
{
6865
int x;
@@ -84,6 +81,7 @@ typedef struct CvLSVMFilterPosition
8481
// used formula H[(j * sizeX + i) * p + k], where
8582
// k - component of feature vector in cell (i, j)
8683
// END OF FILTER DESCRIPTION
84+
8785
typedef struct CvLSVMFilterObjectCaskade{
8886
CvLSVMFilterPosition V;
8987
float fineFunction[4];
@@ -106,6 +104,7 @@ typedef struct CvLSVMFilterObjectCaskade{
106104
// filters - root and part filters for all model components
107105
// b - biases for all model components
108106
// score_threshold - confidence level threshold
107+
109108
typedef struct CvLatentSvmDetectorCaskade
110109
{
111110
int num_filters;
@@ -118,77 +117,7 @@ typedef struct CvLatentSvmDetectorCaskade
118117
int pca_size;
119118
} CvLatentSvmDetectorCaskade;
120119

121-
// data type: STRUCT CvObjectDetection
122-
// structure contains the bounding box and confidence level for detected object
123-
// rect - bounding box for a detected object
124-
// score - confidence level
125-
typedef struct CvObjectDetection
126-
{
127-
CvRect rect;
128-
float score;
129-
} CvObjectDetection;
130-
}
131-
//////////////// Object Detection using Latent SVM //////////////
132-
133-
134-
/*
135-
// load trained detector from a file
136-
//
137-
// API
138-
// CvLatentSvmDetector* cvLoadLatentSvmDetector(const char* filename);
139-
// INPUT
140-
// filename - path to the file containing the parameters of
141-
- trained Latent SVM detector
142-
// OUTPUT
143-
// trained Latent SVM detector in internal representation
144-
*/
145-
namespace cv
146-
{
147-
namespace lsvmc
148-
{
149-
CVAPI(CvLatentSvmDetectorCaskade*) cvLoadLatentSvmDetectorCaskade(const char* filename);
150-
151-
/*
152-
// release memory allocated for CvLatentSvmDetector structure
153-
//
154-
// API
155-
// void cvReleaseLatentSvmDetector(CvLatentSvmDetector** detector);
156-
// INPUT
157-
// detector - CvLatentSvmDetector structure to be released
158-
// OUTPUT
159-
*/
160-
CVAPI(void) cvReleaseLatentSvmDetectorCaskade(CvLatentSvmDetectorCaskade** detector);
161-
/*
162-
// find rectangular regions in the given image that are likely
163-
// to contain objects and corresponding confidence levels
164-
//
165-
// API
166-
// CvSeq* cvLatentSvmDetectObjects(const IplImage* image,
167-
// CvLatentSvmDetector* detector,
168-
// CvMemStorage* storage,
169-
// float overlap_threshold = 0.5f,
170-
// int numThreads = -1);
171-
// INPUT
172-
// image - image to detect objects in
173-
// detector - Latent SVM detector in internal representation
174-
// storage - memory storage to store the resultant sequence
175-
// of the object candidate rectangles
176-
// overlap_threshold - threshold for the non-maximum suppression algorithm
177-
= 0.5f [P. Felzenszwalb, R. Girshick, D. McAllester Cascade
178-
// Object Detection with Deformable Part Models
179-
// IEEE Conference on Computer Vision and Pattern Recognition (CVPR), 2010]
180-
// OUTPUT
181-
// sequence of detected objects (bounding boxes and confidence levels stored in CvObjectDetection structures)
182-
*/
183-
CVAPI(CvSeq*) cvLatentSvmDetectObjectsCaskade(IplImage* image,
184-
CvLatentSvmDetectorCaskade* detector,
185-
CvMemStorage* storage,
186-
float overlap_threshold CV_DEFAULT(0.5f));
187-
}
188120
}
189-
#ifdef __cplusplus
190-
191-
192121

193122
namespace cv
194123
{
@@ -224,8 +153,8 @@ class CV_EXPORTS LatentSvmDetector
224153
virtual bool empty() const;
225154
bool load( const std::vector<std::string>& filenames, const std::vector<std::string>& classNames=std::vector<std::string>() );
226155

227-
virtual void detect( const Mat& image,
228-
std::vector<ObjectDetection>& objectDetections,
156+
virtual void detect(const Mat& image,
157+
CV_OUT std::vector<ObjectDetection>& objects,
229158
float overlapThreshold=0.5f);
230159

231160
const std::vector<std::string>& getClassNames() const;
@@ -239,5 +168,3 @@ class CV_EXPORTS LatentSvmDetector
239168
} // namespace cv
240169

241170
#endif
242-
243-
#endif

modules/latentsvm/src/lsvmc_latentsvmdetector.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ namespace cv
4747
namespace lsvmc
4848
{
4949

50+
// data type: STRUCT CvObjectDetection
51+
// structure contains the bounding box and confidence level for detected object
52+
// rect - bounding box for a detected object
53+
// score - confidence level
54+
55+
typedef struct CvObjectDetection
56+
{
57+
cv::Rect rect;
58+
float score;
59+
} CvObjectDetection;
60+
5061
std::string extractModelName( const std::string& filename );
5162

5263
const int pca_size = 31;
@@ -99,7 +110,7 @@ CvLatentSvmDetectorCaskade* cvLoadLatentSvmDetectorCaskade(const char* filename)
99110
// detector - CvLatentSvmDetectorCaskade structure to be released
100111
// OUTPUT
101112
*/
102-
CVAPI(void) cvReleaseLatentSvmDetectorCaskade(CvLatentSvmDetectorCaskade** detector)
113+
void cvReleaseLatentSvmDetectorCaskade(CvLatentSvmDetectorCaskade** detector)
103114
{
104115
free((*detector)->b);
105116
free((*detector)->num_part_filters);

modules/latentsvm/src/precomp.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
#include <deque>
5252
#endif
5353

54-
#include "opencv2/latentsvm/latentsvm.hpp"
54+
#include "opencv2/latentsvm.hpp"
5555
#include "opencv2/imgproc.hpp"
5656
#include "opencv2/imgproc/imgproc_c.h"
5757
#include "opencv2/core/core_c.h"

modules/latentsvm/test/test_latentsvmdetector_caskade.cpp

Lines changed: 1 addition & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#include "test_precomp.hpp"
4444

4545
#include <string>
46-
#include "opencv2/highgui/highgui_c.h"
46+
//#include "opencv2/highgui/highgui_c.h"
4747

4848
#ifdef HAVE_CVCONFIG_H
4949
#include "cvconfig.h"
@@ -55,85 +55,8 @@
5555

5656
using namespace cv;
5757

58-
const int num_detections = 1;
59-
const float true_scores[] = {-0.83f};
6058
const float score_thr = 0.05f;
61-
const CvRect true_bounding_boxes[] = {cvRect(0, 0, 340, 485)};
6259

63-
class CV_LatentSVMDetectorCaskadeTest : public cvtest::BaseTest
64-
{
65-
protected:
66-
void run(int);
67-
bool isEqual(CvRect r1, CvRect r2, int eps);
68-
};
69-
70-
bool CV_LatentSVMDetectorCaskadeTest::isEqual(CvRect r1, CvRect r2, int eps)
71-
{
72-
return (std::abs(r1.x - r2.x) <= eps
73-
&& std::abs(r1.y - r2.y) <= eps
74-
&& std::abs(r1.width - r2.width) <= eps
75-
&& std::abs(r1.height - r2.height) <= eps);
76-
}
77-
78-
void CV_LatentSVMDetectorCaskadeTest::run( int /* start_from */)
79-
{
80-
std::string img_path = std::string(ts->get_data_path()) + "cat.png";
81-
std::string model_path = std::string(ts->get_data_path()) + "models_VOC2007_caskade/cat.xml";
82-
83-
#ifdef HAVE_TBB
84-
int numThreads = 2;
85-
tbb::task_scheduler_init init(tbb::task_scheduler_init::deferred);
86-
init.initialize(numThreads);
87-
#endif
88-
89-
IplImage* image = cvLoadImage(img_path.c_str());
90-
if (!image)
91-
{
92-
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
93-
return;
94-
}
95-
96-
CvLatentSvmDetectorCaskade* detector;
97-
detector = cv::lsvmc::cvLoadLatentSvmDetectorCaskade(model_path.c_str());
98-
if (!detector)
99-
{
100-
ts->set_failed_test_info( cvtest::TS::FAIL_INVALID_TEST_DATA );
101-
cvReleaseImage(&image);
102-
return;
103-
}
104-
105-
CvMemStorage* storage = cvCreateMemStorage(0);
106-
CvSeq* detections = 0;
107-
detections = cv::lsvmc::cvLatentSvmDetectObjectsCaskade(image, detector, storage, 0.5f);
108-
109-
if (detections->total != num_detections)
110-
{
111-
ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH );
112-
}
113-
else
114-
{
115-
ts->set_failed_test_info(cvtest::TS::OK);
116-
for (int i = 0; i < detections->total; i++)
117-
{
118-
CvObjectDetection detection = *(CvObjectDetection*)cvGetSeqElem( detections, i );
119-
CvRect bounding_box = detection.rect;
120-
float score = detection.score;
121-
if ((!isEqual(bounding_box, true_bounding_boxes[i], 1)) || (fabs(score - true_scores[i]) > score_thr))
122-
{
123-
ts->set_failed_test_info( cvtest::TS::FAIL_MISMATCH );
124-
break;
125-
}
126-
}
127-
}
128-
#ifdef HAVE_TBB
129-
init.terminate();
130-
#endif
131-
cvReleaseMemStorage( &storage );
132-
cv::lsvmc::cvReleaseLatentSvmDetectorCaskade( &detector );
133-
cvReleaseImage( &image );
134-
}
135-
136-
// Test for c++ version of Latent SVM
13760

13861
class LatentSVMDetectorCaskadeTest : public cvtest::BaseTest
13962
{
@@ -307,5 +230,4 @@ void LatentSVMDetectorCaskadeTest::run( int /* start_from */)
307230
ts->set_failed_test_info( cvtest::TS::OK);
308231
}
309232

310-
TEST(Objdetect_LatentSVMDetectorCaskade_c, regression) { CV_LatentSVMDetectorCaskadeTest test; test.safe_run(); }
311233
TEST(Objdetect_LatentSVMDetectorCaskade_cpp, regression) { LatentSVMDetectorCaskadeTest test; test.safe_run(); }

modules/latentsvm/test/test_precomp.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#define __OPENCV_TEST_PRECOMP_HPP__
1111

1212
#include "opencv2/ts.hpp"
13-
#include "opencv2/latentsvm/latentsvm.hpp"
13+
#include "opencv2/latentsvm.hpp"
1414
#include "opencv2/imgproc.hpp"
1515
#include "opencv2/highgui.hpp"
1616

0 commit comments

Comments
 (0)