Skip to content

Commit 83fef80

Browse files
committedMar 28, 2017
Added CV_OUT in process() of selective search segmentation module and python sample.
1 parent 478baf9 commit 83fef80

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed
 

‎modules/ximgproc/include/opencv2/ximgproc/segmentation.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ namespace cv {
236236
/** @brief Based on all images, graph segmentations and stragies, computes all possible rects and return them
237237
@param rects The list of rects. The first ones are more relevents than the lasts ones.
238238
*/
239-
CV_WRAP virtual void process(std::vector<Rect>& rects) = 0;
239+
CV_WRAP virtual void process(CV_OUT std::vector<Rect>& rects) = 0;
240240
};
241241

242242
/** @brief Create a new SelectiveSearchSegmentation class.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env python
2+
3+
'''
4+
A program demonstrating the use and capabilities of a particular image segmentation algorithm described
5+
in Jasper R. R. Uijlings, Koen E. A. van de Sande, Theo Gevers, Arnold W. M. Smeulders:
6+
"Selective Search for Object Recognition"
7+
International Journal of Computer Vision, Volume 104 (2), page 154-171, 2013
8+
Usage:
9+
./selectivesearchsegmentation_demo.py input_image (single|fast|quality)
10+
Use "a" to display less rects, 'd' to display more rects, "q" to quit.
11+
'''
12+
13+
import cv2
14+
import sys
15+
16+
if __name__ == '__main__':
17+
img = cv2.imread(sys.argv[1])
18+
19+
cv2.setUseOptimized(True)
20+
cv2.setNumThreads(8)
21+
22+
gs = cv2.ximgproc.segmentation.createSelectiveSearchSegmentation()
23+
gs.setBaseImage(img)
24+
25+
if (sys.argv[2][0] == 's'):
26+
gs.switchToSingleStrategy()
27+
28+
elif (sys.argv[2][0] == 'f'):
29+
gs.switchToSelectiveSearchFast()
30+
31+
elif (sys.argv[2][0] == 'q'):
32+
gs.switchToSelectiveSearchQuality()
33+
else:
34+
print(__doc__)
35+
sys.exit(1)
36+
37+
rects = gs.process()
38+
nb_rects = 10
39+
40+
while True:
41+
wimg = img.copy()
42+
43+
for i in range(len(rects)):
44+
if (i < nb_rects):
45+
x, y, w, h = rects[i]
46+
cv2.rectangle(wimg, (x, y), (x+w, y+h), (0, 255, 0), 1, cv2.LINE_AA)
47+
48+
cv2.imshow("Output", wimg);
49+
c = cv2.waitKey()
50+
51+
if (c == 100):
52+
nb_rects += 10
53+
54+
elif (c == 97 and nb_rects > 10):
55+
nb_rects -= 10
56+
57+
elif (c == 113):
58+
break
59+
60+
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)
Please sign in to comment.