Skip to content

Commit da29f71

Browse files
committed
Merge pull request #1137 from paroj:linemod_py
2 parents 32b3b4d + 621d6c2 commit da29f71

File tree

2 files changed

+96
-50
lines changed

2 files changed

+96
-50
lines changed

modules/rgbd/include/opencv2/rgbd/linemod.hpp

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,27 @@ namespace linemod {
6060
/**
6161
* \brief Discriminant feature described by its location and label.
6262
*/
63-
struct CV_EXPORTS Feature
63+
struct CV_EXPORTS_W_SIMPLE Feature
6464
{
65-
int x; ///< x offset
66-
int y; ///< y offset
67-
int label; ///< Quantization
65+
CV_PROP_RW int x; ///< x offset
66+
CV_PROP_RW int y; ///< y offset
67+
CV_PROP_RW int label; ///< Quantization
6868

69-
Feature() : x(0), y(0), label(0) {}
70-
Feature(int x, int y, int label);
69+
CV_WRAP Feature() : x(0), y(0), label(0) {}
70+
CV_WRAP Feature(int x, int y, int label);
7171

7272
void read(const FileNode& fn);
7373
void write(FileStorage& fs) const;
7474
};
7575

7676
inline Feature::Feature(int _x, int _y, int _label) : x(_x), y(_y), label(_label) {}
7777

78-
struct CV_EXPORTS Template
78+
struct CV_EXPORTS_W_SIMPLE Template
7979
{
80-
int width;
81-
int height;
82-
int pyramid_level;
83-
std::vector<Feature> features;
80+
CV_PROP int width;
81+
CV_PROP int height;
82+
CV_PROP int pyramid_level;
83+
CV_PROP std::vector<Feature> features;
8484

8585
void read(const FileNode& fn);
8686
void write(FileStorage& fs) const;
@@ -89,7 +89,7 @@ struct CV_EXPORTS Template
8989
/**
9090
* \brief Represents a modality operating over an image pyramid.
9191
*/
92-
class QuantizedPyramid
92+
class CV_EXPORTS_W QuantizedPyramid
9393
{
9494
public:
9595
// Virtual destructor
@@ -101,21 +101,21 @@ class QuantizedPyramid
101101
* \param[out] dst The destination 8-bit image. For each pixel at most one bit is set,
102102
* representing its classification.
103103
*/
104-
virtual void quantize(Mat& dst) const =0;
104+
CV_WRAP virtual void quantize(CV_OUT Mat& dst) const =0;
105105

106106
/**
107107
* \brief Extract most discriminant features at current pyramid level to form a new template.
108108
*
109109
* \param[out] templ The new template.
110110
*/
111-
virtual bool extractTemplate(Template& templ) const =0;
111+
CV_WRAP virtual bool extractTemplate(CV_OUT Template& templ) const =0;
112112

113113
/**
114114
* \brief Go to the next pyramid level.
115115
*
116116
* \todo Allow pyramid scale factor other than 2
117117
*/
118-
virtual void pyrDown() =0;
118+
CV_WRAP virtual void pyrDown() =0;
119119

120120
protected:
121121
/// Candidate feature with a score
@@ -153,7 +153,7 @@ inline QuantizedPyramid::Candidate::Candidate(int x, int y, int label, float _sc
153153
*
154154
* \todo Max response, to allow optimization of summing (255/MAX) features as uint8
155155
*/
156-
class CV_EXPORTS Modality
156+
class CV_EXPORTS_W Modality
157157
{
158158
public:
159159
// Virtual destructor
@@ -166,15 +166,15 @@ class CV_EXPORTS Modality
166166
* \param[in] mask Optional mask. If not empty, unmasked pixels are set to zero
167167
* in quantized image and cannot be extracted as features.
168168
*/
169-
Ptr<QuantizedPyramid> process(const Mat& src,
169+
CV_WRAP Ptr<QuantizedPyramid> process(const Mat& src,
170170
const Mat& mask = Mat()) const
171171
{
172172
return processImpl(src, mask);
173173
}
174174

175-
virtual String name() const =0;
175+
CV_WRAP virtual String name() const =0;
176176

177-
virtual void read(const FileNode& fn) =0;
177+
CV_WRAP virtual void read(const FileNode& fn) =0;
178178
virtual void write(FileStorage& fs) const =0;
179179

180180
/**
@@ -184,12 +184,12 @@ class CV_EXPORTS Modality
184184
* - "ColorGradient"
185185
* - "DepthNormal"
186186
*/
187-
static Ptr<Modality> create(const String& modality_type);
187+
CV_WRAP static Ptr<Modality> create(const String& modality_type);
188188

189189
/**
190190
* \brief Load a modality from file.
191191
*/
192-
static Ptr<Modality> create(const FileNode& fn);
192+
CV_WRAP static Ptr<Modality> create(const FileNode& fn);
193193

194194
protected:
195195
// Indirection is because process() has a default parameter.
@@ -274,18 +274,18 @@ class CV_EXPORTS DepthNormal : public Modality
274274
/**
275275
* \brief Debug function to colormap a quantized image for viewing.
276276
*/
277-
void colormap(const Mat& quantized, Mat& dst);
277+
CV_EXPORTS_W void colormap(const Mat& quantized, CV_OUT Mat& dst);
278278

279279
/**
280280
* \brief Represents a successful template match.
281281
*/
282-
struct CV_EXPORTS Match
282+
struct CV_EXPORTS_W_SIMPLE Match
283283
{
284-
Match()
284+
CV_WRAP Match()
285285
{
286286
}
287287

288-
Match(int x, int y, float similarity, const String& class_id, int template_id);
288+
CV_WRAP Match(int x, int y, float similarity, const String& class_id, int template_id);
289289

290290
/// Sort matches with high similarity to the front
291291
bool operator<(const Match& rhs) const
@@ -302,11 +302,11 @@ struct CV_EXPORTS Match
302302
return x == rhs.x && y == rhs.y && similarity == rhs.similarity && class_id == rhs.class_id;
303303
}
304304

305-
int x;
306-
int y;
307-
float similarity;
308-
String class_id;
309-
int template_id;
305+
CV_PROP_RW int x;
306+
CV_PROP_RW int y;
307+
CV_PROP_RW float similarity;
308+
CV_PROP_RW String class_id;
309+
CV_PROP_RW int template_id;
310310
};
311311

312312
inline
@@ -318,13 +318,13 @@ Match::Match(int _x, int _y, float _similarity, const String& _class_id, int _te
318318
* \brief Object detector using the LINE template matching algorithm with any set of
319319
* modalities.
320320
*/
321-
class CV_EXPORTS Detector
321+
class CV_EXPORTS_W Detector
322322
{
323323
public:
324324
/**
325325
* \brief Empty constructor, initialize with read().
326326
*/
327-
Detector();
327+
CV_WRAP Detector();
328328

329329
/**
330330
* \brief Constructor.
@@ -333,7 +333,7 @@ class CV_EXPORTS Detector
333333
* \param T_pyramid Value of the sampling step T at each pyramid level. The
334334
* number of pyramid levels is T_pyramid.size().
335335
*/
336-
Detector(const std::vector< Ptr<Modality> >& modalities, const std::vector<int>& T_pyramid);
336+
CV_WRAP Detector(const std::vector< Ptr<Modality> >& modalities, const std::vector<int>& T_pyramid);
337337

338338
/**
339339
* \brief Detect objects by template matching.
@@ -350,7 +350,7 @@ class CV_EXPORTS Detector
350350
* the same size as sources. Each element must be
351351
* empty or the same size as its corresponding source.
352352
*/
353-
void match(const std::vector<Mat>& sources, float threshold, std::vector<Match>& matches,
353+
CV_WRAP void match(const std::vector<Mat>& sources, float threshold, CV_OUT std::vector<Match>& matches,
354354
const std::vector<String>& class_ids = std::vector<String>(),
355355
OutputArrayOfArrays quantized_images = noArray(),
356356
const std::vector<Mat>& masks = std::vector<Mat>()) const;
@@ -365,55 +365,55 @@ class CV_EXPORTS Detector
365365
*
366366
* \return Template ID, or -1 if failed to extract a valid template.
367367
*/
368-
int addTemplate(const std::vector<Mat>& sources, const String& class_id,
369-
const Mat& object_mask, Rect* bounding_box = NULL);
368+
CV_WRAP int addTemplate(const std::vector<Mat>& sources, const String& class_id,
369+
const Mat& object_mask, CV_OUT Rect* bounding_box = NULL);
370370

371371
/**
372372
* \brief Add a new object template computed by external means.
373373
*/
374-
int addSyntheticTemplate(const std::vector<Template>& templates, const String& class_id);
374+
CV_WRAP int addSyntheticTemplate(const std::vector<Template>& templates, const String& class_id);
375375

376376
/**
377377
* \brief Get the modalities used by this detector.
378378
*
379379
* You are not permitted to add/remove modalities, but you may dynamic_cast them to
380380
* tweak parameters.
381381
*/
382-
const std::vector< Ptr<Modality> >& getModalities() const { return modalities; }
382+
CV_WRAP const std::vector< Ptr<Modality> >& getModalities() const { return modalities; }
383383

384384
/**
385385
* \brief Get sampling step T at pyramid_level.
386386
*/
387-
int getT(int pyramid_level) const { return T_at_level[pyramid_level]; }
387+
CV_WRAP int getT(int pyramid_level) const { return T_at_level[pyramid_level]; }
388388

389389
/**
390390
* \brief Get number of pyramid levels used by this detector.
391391
*/
392-
int pyramidLevels() const { return pyramid_levels; }
392+
CV_WRAP int pyramidLevels() const { return pyramid_levels; }
393393

394394
/**
395395
* \brief Get the template pyramid identified by template_id.
396396
*
397397
* For example, with 2 modalities (Gradient, Normal) and two pyramid levels
398398
* (L0, L1), the order is (GradientL0, NormalL0, GradientL1, NormalL1).
399399
*/
400-
const std::vector<Template>& getTemplates(const String& class_id, int template_id) const;
400+
CV_WRAP const std::vector<Template>& getTemplates(const String& class_id, int template_id) const;
401401

402-
int numTemplates() const;
403-
int numTemplates(const String& class_id) const;
404-
int numClasses() const { return static_cast<int>(class_templates.size()); }
402+
CV_WRAP int numTemplates() const;
403+
CV_WRAP int numTemplates(const String& class_id) const;
404+
CV_WRAP int numClasses() const { return static_cast<int>(class_templates.size()); }
405405

406-
std::vector<String> classIds() const;
406+
CV_WRAP std::vector<String> classIds() const;
407407

408-
void read(const FileNode& fn);
408+
CV_WRAP void read(const FileNode& fn);
409409
void write(FileStorage& fs) const;
410410

411411
String readClass(const FileNode& fn, const String &class_id_override = "");
412412
void writeClass(const String& class_id, FileStorage& fs) const;
413413

414-
void readClasses(const std::vector<String>& class_ids,
414+
CV_WRAP void readClasses(const std::vector<String>& class_ids,
415415
const String& format = "templates_%s.yml.gz");
416-
void writeClasses(const String& format = "templates_%s.yml.gz") const;
416+
CV_WRAP void writeClasses(const String& format = "templates_%s.yml.gz") const;
417417

418418
protected:
419419
std::vector< Ptr<Modality> > modalities;
@@ -440,15 +440,15 @@ class CV_EXPORTS Detector
440440
*
441441
* Default parameter settings suitable for VGA images.
442442
*/
443-
CV_EXPORTS Ptr<Detector> getDefaultLINE();
443+
CV_EXPORTS_W Ptr<linemod::Detector> getDefaultLINE();
444444

445445
/**
446446
* \brief Factory function for detector using LINE-MOD algorithm with color gradients
447447
* and depth normals.
448448
*
449449
* Default parameter settings suitable for VGA images.
450450
*/
451-
CV_EXPORTS Ptr<Detector> getDefaultLINEMOD();
451+
CV_EXPORTS_W Ptr<linemod::Detector> getDefaultLINEMOD();
452452

453453
//! @}
454454

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#ifdef HAVE_OPENCV_RGBD
2+
#include "opencv2/core/saturate.hpp"
3+
4+
template<> struct pyopencvVecConverter<linemod::Match>
5+
{
6+
static bool to(PyObject* obj, std::vector<linemod::Match>& value, const ArgInfo info)
7+
{
8+
return pyopencv_to_generic_vec(obj, value, info);
9+
}
10+
11+
static PyObject* from(const std::vector<linemod::Match>& value)
12+
{
13+
return pyopencv_from_generic_vec(value);
14+
}
15+
};
16+
17+
template<> struct pyopencvVecConverter<linemod::Template>
18+
{
19+
static bool to(PyObject* obj, std::vector<linemod::Template>& value, const ArgInfo info)
20+
{
21+
return pyopencv_to_generic_vec(obj, value, info);
22+
}
23+
24+
static PyObject* from(const std::vector<linemod::Template>& value)
25+
{
26+
return pyopencv_from_generic_vec(value);
27+
}
28+
};
29+
30+
template<> struct pyopencvVecConverter<Ptr<linemod::Modality> >
31+
{
32+
static bool to(PyObject* obj, std::vector<Ptr<linemod::Modality> >& value, const ArgInfo info)
33+
{
34+
return pyopencv_to_generic_vec(obj, value, info);
35+
}
36+
37+
static PyObject* from(const std::vector<Ptr<linemod::Modality> >& value)
38+
{
39+
return pyopencv_from_generic_vec(value);
40+
}
41+
};
42+
43+
typedef std::vector<linemod::Match> vector_Match;
44+
typedef std::vector<linemod::Template> vector_Template;
45+
typedef std::vector<Ptr<linemod::Modality> > vector_Ptr_Modality;
46+
#endif

0 commit comments

Comments
 (0)