Skip to content

Commit c915bd4

Browse files
author
Dinar Ahmatnurov
committed
reworking interface;
1 parent 3ee04c6 commit c915bd4

17 files changed

+184
-212
lines changed

modules/latentsvm/include/opencv2/latentsvm.hpp

Lines changed: 15 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -43,100 +43,22 @@
4343
#define __OPENCV_OBJDETECT_HPP__
4444

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

4847
#include <map>
4948
#include <vector>
5049
#include <string>
5150

52-
extern "C" {
53-
54-
/****************************************************************************************\
55-
* Latent SVM Object Detection functions *
56-
\****************************************************************************************/
57-
58-
// DataType: STRUCT position
59-
// Structure describes the position of the filter in the feature pyramid
60-
// l - level in the feature pyramid
61-
// (x, y) - coordinate in level l
62-
63-
typedef struct CvLSVMFilterPosition
64-
{
65-
int x;
66-
int y;
67-
int l;
68-
} CvLSVMFilterPosition;
69-
70-
// DataType: STRUCT filterObject
71-
// Description of the filter, which corresponds to the part of the object
72-
// V - ideal (penalty = 0) position of the partial filter
73-
// from the root filter position (V_i in the paper)
74-
// penaltyFunction - vector describes penalty function (d_i in the paper)
75-
// pf[0] * x + pf[1] * y + pf[2] * x^2 + pf[3] * y^2
76-
// FILTER DESCRIPTION
77-
// Rectangular map (sizeX x sizeY),
78-
// every cell stores feature vector (dimension = p)
79-
// H - matrix of feature vectors
80-
// to set and get feature vectors (i,j)
81-
// used formula H[(j * sizeX + i) * p + k], where
82-
// k - component of feature vector in cell (i, j)
83-
// END OF FILTER DESCRIPTION
84-
85-
typedef struct CvLSVMFilterObjectCaskade{
86-
CvLSVMFilterPosition V;
87-
float fineFunction[4];
88-
int sizeX;
89-
int sizeY;
90-
int numFeatures;
91-
float *H;
92-
float *H_PCA;
93-
float Hypothesis, Deformation;
94-
float Hypothesis_PCA, Deformation_PCA;
95-
int deltaX;
96-
int deltaY;
97-
} CvLSVMFilterObjectCaskade;
98-
99-
// data type: STRUCT CvLatentSvmDetector
100-
// structure contains internal representation of trained Latent SVM detector
101-
// num_filters - total number of filters (root plus part) in model
102-
// num_components - number of components in model
103-
// num_part_filters - array containing number of part filters for each component
104-
// filters - root and part filters for all model components
105-
// b - biases for all model components
106-
// score_threshold - confidence level threshold
107-
108-
typedef struct CvLatentSvmDetectorCaskade
109-
{
110-
int num_filters;
111-
int num_components;
112-
int* num_part_filters;
113-
CvLSVMFilterObjectCaskade** filters;
114-
float* b;
115-
float score_threshold;
116-
float *pca;
117-
int pca_size;
118-
} CvLatentSvmDetectorCaskade;
119-
120-
}
121-
12251
namespace cv
12352
{
12453

125-
///////////////////////////// Object Detection ////////////////////////////
126-
127-
/*
128-
* This is a class wrapping up the structure CvLatentSvmDetector and functions working with it.
129-
* The class goals are:
130-
* 1) provide c++ interface;
131-
* 2) make it possible to load and detect more than one class (model) unlike CvLatentSvmDetector.
132-
*/
133-
134-
namespace lsvmc
54+
namespace lsvm
13555
{
136-
class CV_EXPORTS LatentSvmDetector
56+
57+
class CV_EXPORTS_W LSVMDetector
13758
{
13859
public:
139-
struct CV_EXPORTS ObjectDetection
60+
61+
struct CV_EXPORTS_W ObjectDetection
14062
{
14163
ObjectDetection();
14264
ObjectDetection( const Rect& rect, float score, int classID=-1 );
@@ -145,26 +67,20 @@ class CV_EXPORTS LatentSvmDetector
14567
int classID;
14668
};
14769

148-
LatentSvmDetector();
149-
LatentSvmDetector( const std::vector<std::string>& filenames, const std::vector<std::string>& classNames=std::vector<std::string>() );
150-
virtual ~LatentSvmDetector();
70+
virtual bool isEmpty() const = 0;
71+
virtual void detect(cv::Mat const &image, CV_OUT std::vector<ObjectDetection> &objects,
72+
float overlapThreshold=0.5f ) = 0;
15173

152-
virtual void clear();
153-
virtual bool empty() const;
154-
bool load( const std::vector<std::string>& filenames, const std::vector<std::string>& classNames=std::vector<std::string>() );
74+
virtual std::vector<std::string> const& getClassNames() const = 0;
75+
virtual size_t getClassCount() const = 0;
15576

156-
virtual void detect(const Mat& image,
157-
CV_OUT std::vector<ObjectDetection>& objects,
158-
float overlapThreshold=0.5f);
77+
static cv::Ptr<LSVMDetector> create(std::vector<std::string> const &filenames,
78+
std::vector<std::string> const &classNames = std::vector<std::string>());
15979

160-
const std::vector<std::string>& getClassNames() const;
161-
size_t getClassCount() const;
162-
163-
private:
164-
std::vector<CvLatentSvmDetectorCaskade*> detectors;
165-
std::vector<std::string> classNames;
80+
virtual ~LSVMDetector(){}
16681
};
167-
}
82+
83+
} // namespace lsvm
16884
} // namespace cv
16985

17086
#endif

modules/latentsvm/src/_lsvmc_function.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
namespace cv
4848
{
49-
namespace lsvmc
49+
namespace lsvm
5050
{
5151

5252
float calcM (int k,int di,int dj, const CvLSVMFeaturePyramidCaskade * H, const CvLSVMFilterObjectCaskade *filter);

modules/latentsvm/src/_lsvmc_latentsvm.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@
5353

5454
namespace cv
5555
{
56-
namespace lsvmc
56+
namespace lsvm
5757
{
5858

59-
6059
//////////////////////////////////////////////////////////////
6160
// Building feature pyramid
6261
// (pyramid constructed both contrast and non-contrast image)

modules/latentsvm/src/_lsvmc_matching.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
namespace cv
5454
{
55-
namespace lsvmc
55+
namespace lsvm
5656
{
5757

5858

modules/latentsvm/src/_lsvmc_parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108

109109
namespace cv
110110
{
111-
namespace lsvmc
111+
namespace lsvm
112112
{
113113

114114
int loadModel(

modules/latentsvm/src/_lsvmc_resizeimg.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
namespace cv
4848
{
49-
namespace lsvmc
49+
namespace lsvm
5050
{
5151

5252
IplImage * resize_opencv (IplImage * img, float scale);

modules/latentsvm/src/_lsvmc_routine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
namespace cv
4949
{
50-
namespace lsvmc
50+
namespace lsvm
5151
{
5252

5353

modules/latentsvm/src/_lsvmc_types.h

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,24 @@
6565
#define VAL_OF_TRUNCATE 0.2f
6666
namespace cv
6767
{
68-
namespace lsvmc
68+
namespace lsvm
6969
{
70-
7170
//////////////////////////////////////////////////////////////
7271
// main data structures //
7372
//////////////////////////////////////////////////////////////
7473

74+
// data type: STRUCT CvObjectDetection
75+
// structure contains the bounding box and confidence level for detected object
76+
// rect - bounding box for a detected object
77+
// score - confidence level
78+
79+
typedef struct CvObjectDetection
80+
{
81+
cv::Rect rect;
82+
float score;
83+
} CvObjectDetection;
84+
85+
7586
// DataType: STRUCT featureMap
7687
// FEATURE MAP DESCRIPTION
7788
// Rectangular map (sizeX x sizeY),
@@ -108,6 +119,68 @@ typedef struct{
108119
int *x;
109120
int *y;
110121
} CvLSVMFilterDisposition;
122+
123+
// DataType: STRUCT position
124+
// Structure describes the position of the filter in the feature pyramid
125+
// l - level in the feature pyramid
126+
// (x, y) - coordinate in level l
127+
128+
typedef struct CvLSVMFilterPosition
129+
{
130+
int x;
131+
int y;
132+
int l;
133+
} CvLSVMFilterPosition;
134+
135+
// DataType: STRUCT filterObject
136+
// Description of the filter, which corresponds to the part of the object
137+
// V - ideal (penalty = 0) position of the partial filter
138+
// from the root filter position (V_i in the paper)
139+
// penaltyFunction - vector describes penalty function (d_i in the paper)
140+
// pf[0] * x + pf[1] * y + pf[2] * x^2 + pf[3] * y^2
141+
// FILTER DESCRIPTION
142+
// Rectangular map (sizeX x sizeY),
143+
// every cell stores feature vector (dimension = p)
144+
// H - matrix of feature vectors
145+
// to set and get feature vectors (i,j)
146+
// used formula H[(j * sizeX + i) * p + k], where
147+
// k - component of feature vector in cell (i, j)
148+
// END OF FILTER DESCRIPTION
149+
150+
typedef struct CvLSVMFilterObjectCaskade{
151+
CvLSVMFilterPosition V;
152+
float fineFunction[4];
153+
int sizeX;
154+
int sizeY;
155+
int numFeatures;
156+
float *H;
157+
float *H_PCA;
158+
float Hypothesis, Deformation;
159+
float Hypothesis_PCA, Deformation_PCA;
160+
int deltaX;
161+
int deltaY;
162+
} CvLSVMFilterObjectCaskade;
163+
164+
// data type: STRUCT CvLatentSvmDetector
165+
// structure contains internal representation of trained Latent SVM detector
166+
// num_filters - total number of filters (root plus part) in model
167+
// num_components - number of components in model
168+
// num_part_filters - array containing number of part filters for each component
169+
// filters - root and part filters for all model components
170+
// b - biases for all model components
171+
// score_threshold - confidence level threshold
172+
173+
typedef struct CvLatentSvmDetectorCaskade
174+
{
175+
int num_filters;
176+
int num_components;
177+
int* num_part_filters;
178+
CvLSVMFilterObjectCaskade** filters;
179+
float* b;
180+
float score_threshold;
181+
float *pca;
182+
int pca_size;
183+
} CvLatentSvmDetectorCaskade;
111184
}
112185
}
113186
#endif

modules/latentsvm/src/lsvmc_featurepyramid.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
namespace cv
6161
{
62-
namespace lsvmc
62+
namespace lsvm
6363
{
6464

6565
int getPathOfFeaturePyramid(IplImage * image,

modules/latentsvm/src/lsvmc_function.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#include "_lsvmc_function.h"
4444
namespace cv
4545
{
46-
namespace lsvmc
46+
namespace lsvm
4747
{
4848

4949
float calcM (int k,int di,int dj, const CvLSVMFeaturePyramidCaskade * H, const CvLSVMFilterObjectCaskade *filter){

0 commit comments

Comments
 (0)