Skip to content

Commit 8292bb2

Browse files
committed
Merge pull request #1697 from dianlujitao:3.4
2 parents 6728369 + e396a67 commit 8292bb2

File tree

3 files changed

+83
-26
lines changed

3 files changed

+83
-26
lines changed

modules/line_descriptor/include/opencv2/line_descriptor/descriptor.hpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -99,73 +99,73 @@ Apart from fields inspired to KeyPoint class, KeyLines stores information about
9999
original image and in octave it was extracted from, about line's length and number of pixels it
100100
covers.
101101
*/
102-
struct CV_EXPORTS KeyLine
102+
struct CV_EXPORTS_W_SIMPLE KeyLine
103103
{
104104
public:
105105
/** orientation of the line */
106-
float angle;
106+
CV_PROP_RW float angle;
107107

108108
/** object ID, that can be used to cluster keylines by the line they represent */
109-
int class_id;
109+
CV_PROP_RW int class_id;
110110

111111
/** octave (pyramid layer), from which the keyline has been extracted */
112-
int octave;
112+
CV_PROP_RW int octave;
113113

114114
/** coordinates of the middlepoint */
115-
Point2f pt;
115+
CV_PROP_RW Point2f pt;
116116

117117
/** the response, by which the strongest keylines have been selected.
118118
It's represented by the ratio between line's length and maximum between
119119
image's width and height */
120-
float response;
120+
CV_PROP_RW float response;
121121

122122
/** minimum area containing line */
123-
float size;
123+
CV_PROP_RW float size;
124124

125125
/** lines's extremes in original image */
126-
float startPointX;
127-
float startPointY;
128-
float endPointX;
129-
float endPointY;
126+
CV_PROP_RW float startPointX;
127+
CV_PROP_RW float startPointY;
128+
CV_PROP_RW float endPointX;
129+
CV_PROP_RW float endPointY;
130130

131131
/** line's extremes in image it was extracted from */
132-
float sPointInOctaveX;
133-
float sPointInOctaveY;
134-
float ePointInOctaveX;
135-
float ePointInOctaveY;
132+
CV_PROP_RW float sPointInOctaveX;
133+
CV_PROP_RW float sPointInOctaveY;
134+
CV_PROP_RW float ePointInOctaveX;
135+
CV_PROP_RW float ePointInOctaveY;
136136

137137
/** the length of line */
138-
float lineLength;
138+
CV_PROP_RW float lineLength;
139139

140140
/** number of pixels covered by the line */
141-
int numOfPixels;
141+
CV_PROP_RW int numOfPixels;
142142

143143
/** Returns the start point of the line in the original image */
144-
Point2f getStartPoint() const
144+
CV_WRAP Point2f getStartPoint() const
145145
{
146146
return Point2f(startPointX, startPointY);
147147
}
148148

149149
/** Returns the end point of the line in the original image */
150-
Point2f getEndPoint() const
150+
CV_WRAP Point2f getEndPoint() const
151151
{
152152
return Point2f(endPointX, endPointY);
153153
}
154154

155155
/** Returns the start point of the line in the octave it was extracted from */
156-
Point2f getStartPointInOctave() const
156+
CV_WRAP Point2f getStartPointInOctave() const
157157
{
158158
return Point2f(sPointInOctaveX, sPointInOctaveY);
159159
}
160160

161161
/** Returns the end point of the line in the octave it was extracted from */
162-
Point2f getEndPointInOctave() const
162+
CV_WRAP Point2f getEndPointInOctave() const
163163
{
164164
return Point2f(ePointInOctaveX, ePointInOctaveY);
165165
}
166166

167167
/** constructor */
168-
KeyLine()
168+
CV_WRAP KeyLine()
169169
{
170170
}
171171
};
@@ -892,7 +892,7 @@ the one used in *BinaryDescriptor* class, data associated to a line's extremes i
892892
in octave it was extracted from, coincide. KeyLine's field *class_id* is used as an index to
893893
indicate the order of extraction of a line inside a single octave.
894894
*/
895-
class CV_EXPORTS LSDDetector : public Algorithm
895+
class CV_EXPORTS_W LSDDetector : public Algorithm
896896
{
897897
public:
898898

@@ -905,7 +905,7 @@ LSDDetector()
905905

906906
/** @brief Creates ad LSDDetector object, using smart pointers.
907907
*/
908-
static Ptr<LSDDetector> createLSDDetector();
908+
CV_WRAP static Ptr<LSDDetector> createLSDDetector();
909909

910910
/** @brief Detect lines inside an image.
911911
@@ -915,7 +915,7 @@ static Ptr<LSDDetector> createLSDDetector();
915915
@param numOctaves number of octaves inside pyramid
916916
@param mask mask matrix to detect only KeyLines of interest
917917
*/
918-
void detect( const Mat& image, CV_OUT std::vector<KeyLine>& keypoints, int scale, int numOctaves, const Mat& mask = Mat() );
918+
CV_WRAP void detect( const Mat& image, CV_OUT std::vector<KeyLine>& keypoints, int scale, int numOctaves, const Mat& mask = Mat() );
919919

920920
/** @overload
921921
@param images input images
@@ -924,7 +924,7 @@ void detect( const Mat& image, CV_OUT std::vector<KeyLine>& keypoints, int scale
924924
@param numOctaves number of octaves inside pyramid
925925
@param masks vector of mask matrices to detect only KeyLines of interest from each input image
926926
*/
927-
void detect( const std::vector<Mat>& images, std::vector<std::vector<KeyLine> >& keylines, int scale, int numOctaves,
927+
CV_WRAP void detect( const std::vector<Mat>& images, std::vector<std::vector<KeyLine> >& keylines, int scale, int numOctaves,
928928
const std::vector<Mat>& masks = std::vector<Mat>() ) const;
929929

930930
private:
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include "opencv2/line_descriptor.hpp"
2+
3+
template<> struct pyopencvVecConverter<line_descriptor::KeyLine>
4+
{
5+
static bool to(PyObject* obj, std::vector<line_descriptor::KeyLine>& value, const ArgInfo info)
6+
{
7+
return pyopencv_to_generic_vec(obj, value, info);
8+
}
9+
10+
static PyObject* from(const std::vector<line_descriptor::KeyLine>& value)
11+
{
12+
return pyopencv_from_generic_vec(value);
13+
}
14+
};
15+
16+
typedef std::vector<line_descriptor::KeyLine> vector_KeyLine;
17+
typedef std::vector<std::vector<line_descriptor::KeyLine> > vector_vector_KeyLine;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python
2+
3+
'''
4+
This example shows the functionalities of lines extraction finished by LSDDetector class.
5+
6+
USAGE: lsd_lines_extraction.py [<path_to_input_image>]
7+
'''
8+
9+
import sys
10+
import cv2 as cv
11+
12+
if __name__ == '__main__':
13+
print(__doc__)
14+
15+
if len(sys.argv) > 1:
16+
fname = sys.argv[1]
17+
else :
18+
fname = '../data/corridor.jpg'
19+
20+
img = cv.imread(fname)
21+
22+
if img is None:
23+
print('Failed to load image file:', fname)
24+
sys.exit(1)
25+
26+
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
27+
28+
lsd = cv.line_descriptor_LSDDetector.createLSDDetector()
29+
30+
lines = lsd.detect(gray, 2, 1)
31+
for kl in lines:
32+
if kl.octave == 0:
33+
# cv.line only accepts integer coordinate
34+
pt1 = (int(kl.startPointX), int(kl.startPointY))
35+
pt2 = (int(kl.endPointX), int(kl.endPointY))
36+
cv.line(img, pt1, pt2, [255, 0, 0], 2)
37+
38+
cv.imshow('output', img)
39+
cv.waitKey(0)
40+
cv.destroyAllWindows()

0 commit comments

Comments
 (0)