ruby-opencv 0.0.9-x86-mswin32 → 0.0.10.pre-x86-mswin32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/History.txt +5 -5
- data/README.md +1 -1
- data/examples/contours/contour_retrieval_modes.rb +139 -139
- data/examples/face_detect.rb +20 -20
- data/examples/houghcircle.rb +22 -22
- data/examples/paint.rb +70 -70
- data/examples/snake.rb +43 -43
- data/ext/opencv/cvcondensation.cpp +282 -282
- data/ext/opencv/cvcondensation.h +49 -49
- data/ext/opencv/cvmat.cpp +6 -6
- data/ext/opencv/cvmatnd.cpp +44 -44
- data/ext/opencv/cvmatnd.h +28 -28
- data/ext/opencv/cvmemstorage.cpp +68 -68
- data/ext/opencv/cvmemstorage.h +53 -53
- data/ext/opencv/cvmoments.h +75 -75
- data/ext/opencv/cvpoint.h +64 -64
- data/ext/opencv/cvpoint2d32f.h +63 -63
- data/ext/opencv/cvpoint3d32f.h +66 -66
- data/ext/opencv/cvrect.h +79 -79
- data/ext/opencv/cvscalar.h +71 -71
- data/ext/opencv/cvsize.h +65 -65
- data/ext/opencv/cvsize2d32f.h +64 -64
- data/ext/opencv/cvslice.h +61 -61
- data/ext/opencv/cvsparsemat.cpp +44 -44
- data/ext/opencv/cvsparsemat.h +28 -28
- data/ext/opencv/cvsurfparams.h +58 -58
- data/ext/opencv/cvsurfpoint.h +52 -52
- data/ext/opencv/cvtermcriteria.h +71 -71
- data/ext/opencv/cvtwopoints.cpp +116 -116
- data/ext/opencv/cvtwopoints.h +51 -51
- data/ext/opencv/cvvideowriter.h +43 -43
- data/ext/opencv/gui.cpp +68 -68
- data/ext/opencv/gui.h +30 -30
- data/ext/opencv/iplconvkernel.h +71 -71
- data/ext/opencv/mouseevent.cpp +181 -181
- data/ext/opencv/mouseevent.h +56 -56
- data/ext/opencv/opencv.cpp +5 -0
- data/ext/opencv/trackbar.h +69 -69
- data/ext/opencv/window.h +66 -66
- data/lib/opencv/version.rb +1 -1
- data/ruby-opencv.gemspec +7 -7
- data/test/test_cvmat_imageprocessing.rb +15 -25
- data/test/test_opencv.rb +7 -2
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cae7dbc907b0156d2e8082f5ffce8aab123eb91d
|
4
|
+
data.tar.gz: e0615ae025ed6350c5fd6da9978e390bdda1c707
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 03ce6cf9070e93fecb01a6c07b4957301e5eec60719537785b777f5f40296c525b38b5fba3220511442f5eac605add2aeb96ec9f6cd166acf1a7fa6abc68498d
|
7
|
+
data.tar.gz: f345414d52ef2435d4a9310d425b575997ad64b3b5b6ab7a88d11de720fc245d2316ac62212e859bbbd686718abda6e24de46738a61f84a656e5fbd14af5d0de
|
data/.gitignore
CHANGED
data/History.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
=== 0.0.6 / 2008-06-27
|
2
|
-
|
3
|
-
* First gem release.
|
4
|
-
|
5
|
-
* Some OpenCV function wrapped.
|
1
|
+
=== 0.0.6 / 2008-06-27
|
2
|
+
|
3
|
+
* First gem release.
|
4
|
+
|
5
|
+
* Some OpenCV function wrapped.
|
data/README.md
CHANGED
@@ -1,139 +1,139 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
#
|
3
|
-
# This file shows the different retrieval modes for contour detection
|
4
|
-
#
|
5
|
-
require "opencv"
|
6
|
-
|
7
|
-
# Load image
|
8
|
-
# The structure of the image is "explained" in bitmap-contours-with-labels.png
|
9
|
-
cvmat = OpenCV::CvMat.load("bitmap-contours.png")
|
10
|
-
|
11
|
-
# "find_contours" does only operate on bitmap images (black/white)
|
12
|
-
mat = OpenCV::CvMat.new(cvmat.rows, cvmat.cols, :cv8u, 1)
|
13
|
-
(cvmat.rows * cvmat.cols).times do |i|
|
14
|
-
mat[i] = (cvmat[i][0] <= 128) ? OpenCV::CvScalar.new(0) : OpenCV::CvScalar.new(255)
|
15
|
-
end
|
16
|
-
|
17
|
-
# find_contours takes two parameters:
|
18
|
-
# 1. Retrieval mode (:mode, defines the structure of the contour sequence returned)
|
19
|
-
# - CV_RETR_LIST (default)
|
20
|
-
# - CV_RETR_EXTERNAL
|
21
|
-
# - CV_RETR_CCOMP
|
22
|
-
# - CV_RETR_TREE
|
23
|
-
# 2. Retrieval Method (:method, how the contours are approximated)
|
24
|
-
# - CV_CHAIN_CODE
|
25
|
-
# - CV_CHAIN_APPROX_NONE
|
26
|
-
# - CV_CHAIN_APPROX_SIMPLE (default)
|
27
|
-
# - CV_CHAIN_APPROX_TC89_L1
|
28
|
-
# - CV_CHAIN_APPROX_T89_KCOS
|
29
|
-
# - CV_LINK_RUNS
|
30
|
-
|
31
|
-
#
|
32
|
-
# The default: CV_RETR_LIST and CV_CHAIN_APPROX_SIMPLE
|
33
|
-
# This produces a flat list of contours that can be traversed with .h_next and .h_prev
|
34
|
-
#
|
35
|
-
puts "Detecting using CV_RETR_LIST and CV_CHAIN_APPROX_SIMPLE"
|
36
|
-
contour = mat.find_contours(:mode => OpenCV::CV_RETR_LIST, :method => OpenCV::CV_CHAIN_APPROX_SIMPLE)
|
37
|
-
cindex=1
|
38
|
-
|
39
|
-
while contour
|
40
|
-
puts "Contour ##{cindex} is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
41
|
-
contour = contour.h_next
|
42
|
-
cindex+=1
|
43
|
-
end
|
44
|
-
|
45
|
-
#
|
46
|
-
# CV_RETR_EXTERNAL retrieves only the outer most non "hole" contour
|
47
|
-
#
|
48
|
-
puts '-'*80
|
49
|
-
puts "Detecting using CV_RETR_EXTERNAL and CV_CHAIN_APPROX_SIMPLE"
|
50
|
-
contour = mat.find_contours(:mode => OpenCV::CV_RETR_EXTERNAL, :method => OpenCV::CV_CHAIN_APPROX_SIMPLE)
|
51
|
-
cindex=1
|
52
|
-
|
53
|
-
while contour
|
54
|
-
puts "Contour ##{cindex} is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
55
|
-
contour = contour.h_next
|
56
|
-
cindex+=1
|
57
|
-
end
|
58
|
-
|
59
|
-
#
|
60
|
-
# CV_RETR_CCOMP organizes the contours in a two level deep stack
|
61
|
-
# The first level holds the contours
|
62
|
-
# The second level contains the holes of the contours in level 1
|
63
|
-
#
|
64
|
-
# C00001 <-> C00000 <-> C000 <-> C0
|
65
|
-
# | |
|
66
|
-
# V V
|
67
|
-
# H0000 H00
|
68
|
-
#
|
69
|
-
puts '-'*80
|
70
|
-
puts "Detecting using CV_RETR_CCOMP and CV_CHAIN_APPROX_SIMPLE"
|
71
|
-
contour = mat.find_contours(:mode => OpenCV::CV_RETR_CCOMP, :method => OpenCV::CV_CHAIN_APPROX_SIMPLE)
|
72
|
-
|
73
|
-
# C00001
|
74
|
-
puts "Contour #1 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
75
|
-
contour = contour.h_next
|
76
|
-
|
77
|
-
# C00000
|
78
|
-
puts "Contour #2 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
79
|
-
contour = contour.h_next
|
80
|
-
|
81
|
-
# C000
|
82
|
-
puts "Contour #3 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
83
|
-
contour_down = contour.v_next
|
84
|
-
|
85
|
-
# H0000
|
86
|
-
puts "Contour #4 is #{contour_down.contour_area} px^2 (width: #{contour_down.bounding_rect.width}, height: #{contour_down.bounding_rect.height}, type: #{(contour_down.hole?)?"hole":"contour"})"
|
87
|
-
contour = contour.h_next
|
88
|
-
|
89
|
-
# C0
|
90
|
-
puts "Contour #5 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
91
|
-
contour_down = contour.v_next
|
92
|
-
|
93
|
-
# H00
|
94
|
-
puts "Contour #6 is #{contour_down.contour_area} px^2 (width: #{contour_down.bounding_rect.width}, height: #{contour_down.bounding_rect.height}, type: #{(contour_down.hole?)?"hole":"contour"})"
|
95
|
-
|
96
|
-
#
|
97
|
-
# CV_RETR_TREE manages the contours in a tree structure
|
98
|
-
# This reconstructs the complete hierarchy of contours and holes that the image displayed
|
99
|
-
#
|
100
|
-
# C0
|
101
|
-
# |
|
102
|
-
# V
|
103
|
-
# H00
|
104
|
-
# |
|
105
|
-
# V
|
106
|
-
# C000
|
107
|
-
# |
|
108
|
-
# V
|
109
|
-
# H0000-------+
|
110
|
-
# | |
|
111
|
-
# V V
|
112
|
-
# C00000 C00001
|
113
|
-
#
|
114
|
-
puts '-'*80
|
115
|
-
puts "Detecting using CV_RETR_TREE and CV_CHAIN_APPROX_SIMPLE"
|
116
|
-
contour = mat.find_contours(:mode => OpenCV::CV_RETR_TREE, :method => OpenCV::CV_CHAIN_APPROX_SIMPLE)
|
117
|
-
|
118
|
-
# C0
|
119
|
-
puts "Contour #1 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
120
|
-
contour = contour.v_next
|
121
|
-
|
122
|
-
# H00
|
123
|
-
puts "Contour #2 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
124
|
-
contour = contour.v_next
|
125
|
-
|
126
|
-
# C000
|
127
|
-
puts "Contour #3 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
128
|
-
contour = contour.v_next
|
129
|
-
|
130
|
-
# H0000
|
131
|
-
puts "Contour #4 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
132
|
-
contour = contour.v_next
|
133
|
-
|
134
|
-
# C00000
|
135
|
-
puts "Contour #5 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
136
|
-
contour_right = contour.h_next
|
137
|
-
|
138
|
-
# C00001
|
139
|
-
puts "Contour #6 is #{contour_right.contour_area} px^2 (width: #{contour_right.bounding_rect.width}, height: #{contour_right.bounding_rect.height}, type: #{(contour_right.hole?)?"hole":"contour"})"
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# This file shows the different retrieval modes for contour detection
|
4
|
+
#
|
5
|
+
require "opencv"
|
6
|
+
|
7
|
+
# Load image
|
8
|
+
# The structure of the image is "explained" in bitmap-contours-with-labels.png
|
9
|
+
cvmat = OpenCV::CvMat.load("bitmap-contours.png")
|
10
|
+
|
11
|
+
# "find_contours" does only operate on bitmap images (black/white)
|
12
|
+
mat = OpenCV::CvMat.new(cvmat.rows, cvmat.cols, :cv8u, 1)
|
13
|
+
(cvmat.rows * cvmat.cols).times do |i|
|
14
|
+
mat[i] = (cvmat[i][0] <= 128) ? OpenCV::CvScalar.new(0) : OpenCV::CvScalar.new(255)
|
15
|
+
end
|
16
|
+
|
17
|
+
# find_contours takes two parameters:
|
18
|
+
# 1. Retrieval mode (:mode, defines the structure of the contour sequence returned)
|
19
|
+
# - CV_RETR_LIST (default)
|
20
|
+
# - CV_RETR_EXTERNAL
|
21
|
+
# - CV_RETR_CCOMP
|
22
|
+
# - CV_RETR_TREE
|
23
|
+
# 2. Retrieval Method (:method, how the contours are approximated)
|
24
|
+
# - CV_CHAIN_CODE
|
25
|
+
# - CV_CHAIN_APPROX_NONE
|
26
|
+
# - CV_CHAIN_APPROX_SIMPLE (default)
|
27
|
+
# - CV_CHAIN_APPROX_TC89_L1
|
28
|
+
# - CV_CHAIN_APPROX_T89_KCOS
|
29
|
+
# - CV_LINK_RUNS
|
30
|
+
|
31
|
+
#
|
32
|
+
# The default: CV_RETR_LIST and CV_CHAIN_APPROX_SIMPLE
|
33
|
+
# This produces a flat list of contours that can be traversed with .h_next and .h_prev
|
34
|
+
#
|
35
|
+
puts "Detecting using CV_RETR_LIST and CV_CHAIN_APPROX_SIMPLE"
|
36
|
+
contour = mat.find_contours(:mode => OpenCV::CV_RETR_LIST, :method => OpenCV::CV_CHAIN_APPROX_SIMPLE)
|
37
|
+
cindex=1
|
38
|
+
|
39
|
+
while contour
|
40
|
+
puts "Contour ##{cindex} is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
41
|
+
contour = contour.h_next
|
42
|
+
cindex+=1
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# CV_RETR_EXTERNAL retrieves only the outer most non "hole" contour
|
47
|
+
#
|
48
|
+
puts '-'*80
|
49
|
+
puts "Detecting using CV_RETR_EXTERNAL and CV_CHAIN_APPROX_SIMPLE"
|
50
|
+
contour = mat.find_contours(:mode => OpenCV::CV_RETR_EXTERNAL, :method => OpenCV::CV_CHAIN_APPROX_SIMPLE)
|
51
|
+
cindex=1
|
52
|
+
|
53
|
+
while contour
|
54
|
+
puts "Contour ##{cindex} is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
55
|
+
contour = contour.h_next
|
56
|
+
cindex+=1
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# CV_RETR_CCOMP organizes the contours in a two level deep stack
|
61
|
+
# The first level holds the contours
|
62
|
+
# The second level contains the holes of the contours in level 1
|
63
|
+
#
|
64
|
+
# C00001 <-> C00000 <-> C000 <-> C0
|
65
|
+
# | |
|
66
|
+
# V V
|
67
|
+
# H0000 H00
|
68
|
+
#
|
69
|
+
puts '-'*80
|
70
|
+
puts "Detecting using CV_RETR_CCOMP and CV_CHAIN_APPROX_SIMPLE"
|
71
|
+
contour = mat.find_contours(:mode => OpenCV::CV_RETR_CCOMP, :method => OpenCV::CV_CHAIN_APPROX_SIMPLE)
|
72
|
+
|
73
|
+
# C00001
|
74
|
+
puts "Contour #1 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
75
|
+
contour = contour.h_next
|
76
|
+
|
77
|
+
# C00000
|
78
|
+
puts "Contour #2 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
79
|
+
contour = contour.h_next
|
80
|
+
|
81
|
+
# C000
|
82
|
+
puts "Contour #3 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
83
|
+
contour_down = contour.v_next
|
84
|
+
|
85
|
+
# H0000
|
86
|
+
puts "Contour #4 is #{contour_down.contour_area} px^2 (width: #{contour_down.bounding_rect.width}, height: #{contour_down.bounding_rect.height}, type: #{(contour_down.hole?)?"hole":"contour"})"
|
87
|
+
contour = contour.h_next
|
88
|
+
|
89
|
+
# C0
|
90
|
+
puts "Contour #5 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
91
|
+
contour_down = contour.v_next
|
92
|
+
|
93
|
+
# H00
|
94
|
+
puts "Contour #6 is #{contour_down.contour_area} px^2 (width: #{contour_down.bounding_rect.width}, height: #{contour_down.bounding_rect.height}, type: #{(contour_down.hole?)?"hole":"contour"})"
|
95
|
+
|
96
|
+
#
|
97
|
+
# CV_RETR_TREE manages the contours in a tree structure
|
98
|
+
# This reconstructs the complete hierarchy of contours and holes that the image displayed
|
99
|
+
#
|
100
|
+
# C0
|
101
|
+
# |
|
102
|
+
# V
|
103
|
+
# H00
|
104
|
+
# |
|
105
|
+
# V
|
106
|
+
# C000
|
107
|
+
# |
|
108
|
+
# V
|
109
|
+
# H0000-------+
|
110
|
+
# | |
|
111
|
+
# V V
|
112
|
+
# C00000 C00001
|
113
|
+
#
|
114
|
+
puts '-'*80
|
115
|
+
puts "Detecting using CV_RETR_TREE and CV_CHAIN_APPROX_SIMPLE"
|
116
|
+
contour = mat.find_contours(:mode => OpenCV::CV_RETR_TREE, :method => OpenCV::CV_CHAIN_APPROX_SIMPLE)
|
117
|
+
|
118
|
+
# C0
|
119
|
+
puts "Contour #1 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
120
|
+
contour = contour.v_next
|
121
|
+
|
122
|
+
# H00
|
123
|
+
puts "Contour #2 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
124
|
+
contour = contour.v_next
|
125
|
+
|
126
|
+
# C000
|
127
|
+
puts "Contour #3 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
128
|
+
contour = contour.v_next
|
129
|
+
|
130
|
+
# H0000
|
131
|
+
puts "Contour #4 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
132
|
+
contour = contour.v_next
|
133
|
+
|
134
|
+
# C00000
|
135
|
+
puts "Contour #5 is #{contour.contour_area} px^2 (width: #{contour.bounding_rect.width}, height: #{contour.bounding_rect.height}, type: #{(contour.hole?)?"hole":"contour"})"
|
136
|
+
contour_right = contour.h_next
|
137
|
+
|
138
|
+
# C00001
|
139
|
+
puts "Contour #6 is #{contour_right.contour_area} px^2 (width: #{contour_right.bounding_rect.width}, height: #{contour_right.bounding_rect.height}, type: #{(contour_right.hole?)?"hole":"contour"})"
|
data/examples/face_detect.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# face_detect.rb
|
3
|
-
require "rubygems"
|
4
|
-
require "opencv"
|
5
|
-
|
6
|
-
include OpenCV
|
7
|
-
|
8
|
-
window = GUI::Window.new("face detect")
|
9
|
-
capture = CvCapture.open
|
10
|
-
detector = CvHaarClassifierCascade::load("./data/haarcascades/haarcascade_frontalface_alt.xml")
|
11
|
-
|
12
|
-
loop {
|
13
|
-
image = capture.query
|
14
|
-
detector.detect_objects(image).each { |rect|
|
15
|
-
image.rectangle! rect.top_left, rect.bottom_right, :color => CvColor::Red
|
16
|
-
}
|
17
|
-
window.show image
|
18
|
-
break if GUI::wait_key(100)
|
19
|
-
}
|
20
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# face_detect.rb
|
3
|
+
require "rubygems"
|
4
|
+
require "opencv"
|
5
|
+
|
6
|
+
include OpenCV
|
7
|
+
|
8
|
+
window = GUI::Window.new("face detect")
|
9
|
+
capture = CvCapture.open
|
10
|
+
detector = CvHaarClassifierCascade::load("./data/haarcascades/haarcascade_frontalface_alt.xml")
|
11
|
+
|
12
|
+
loop {
|
13
|
+
image = capture.query
|
14
|
+
detector.detect_objects(image).each { |rect|
|
15
|
+
image.rectangle! rect.top_left, rect.bottom_right, :color => CvColor::Red
|
16
|
+
}
|
17
|
+
window.show image
|
18
|
+
break if GUI::wait_key(100)
|
19
|
+
}
|
20
|
+
|
data/examples/houghcircle.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# houghcircle.rb
|
3
|
-
require "rubygems"
|
4
|
-
require "opencv"
|
5
|
-
include OpenCV
|
6
|
-
|
7
|
-
original_window = GUI::Window.new "original"
|
8
|
-
hough_window = GUI::Window.new "hough circles"
|
9
|
-
|
10
|
-
image = IplImage::load "stuff.jpg"
|
11
|
-
gray = image.BGR2GRAY
|
12
|
-
|
13
|
-
result = image.clone
|
14
|
-
original_window.show image
|
15
|
-
detect = gray.hough_circles(CV_HOUGH_GRADIENT, 2.0, 10, 200, 50)
|
16
|
-
puts detect.size
|
17
|
-
detect.each{|circle|
|
18
|
-
puts "#{circle.center.x},#{circle.center.y} - #{circle.radius}"
|
19
|
-
result.circle! circle.center, circle.radius, :color => CvColor::Red, :thickness => 3
|
20
|
-
}
|
21
|
-
hough_window.show result
|
22
|
-
GUI::wait_key
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# houghcircle.rb
|
3
|
+
require "rubygems"
|
4
|
+
require "opencv"
|
5
|
+
include OpenCV
|
6
|
+
|
7
|
+
original_window = GUI::Window.new "original"
|
8
|
+
hough_window = GUI::Window.new "hough circles"
|
9
|
+
|
10
|
+
image = IplImage::load "stuff.jpg"
|
11
|
+
gray = image.BGR2GRAY
|
12
|
+
|
13
|
+
result = image.clone
|
14
|
+
original_window.show image
|
15
|
+
detect = gray.hough_circles(CV_HOUGH_GRADIENT, 2.0, 10, 200, 50)
|
16
|
+
puts detect.size
|
17
|
+
detect.each{|circle|
|
18
|
+
puts "#{circle.center.x},#{circle.center.y} - #{circle.radius}"
|
19
|
+
result.circle! circle.center, circle.radius, :color => CvColor::Red, :thickness => 3
|
20
|
+
}
|
21
|
+
hough_window.show result
|
22
|
+
GUI::wait_key
|
data/examples/paint.rb
CHANGED
@@ -1,70 +1,70 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# paint.rb
|
3
|
-
require "rubygems"
|
4
|
-
require "opencv"
|
5
|
-
|
6
|
-
include OpenCV
|
7
|
-
|
8
|
-
window = GUI::Window.new("free canvas")
|
9
|
-
canvas = CvMat.new(500, 500, CV_8U, 3).fill!(CvColor::White) # create white canvas
|
10
|
-
window.show canvas
|
11
|
-
|
12
|
-
colors = CvColor::constants.collect{ |i| i.to_s }
|
13
|
-
|
14
|
-
usage =<<USAGE
|
15
|
-
[mouse]
|
16
|
-
drag - draw
|
17
|
-
right button - fill by color
|
18
|
-
[keyborad]
|
19
|
-
1 to 9 - change thickness of line
|
20
|
-
type color name - change color
|
21
|
-
esc - exit
|
22
|
-
USAGE
|
23
|
-
puts usage
|
24
|
-
|
25
|
-
# drawing option
|
26
|
-
opt = {
|
27
|
-
:color => CvColor::Black,
|
28
|
-
:tickness => 1
|
29
|
-
}
|
30
|
-
|
31
|
-
point = nil
|
32
|
-
window.on_mouse{ |m|
|
33
|
-
case m.event
|
34
|
-
when :move
|
35
|
-
if m.left_button?
|
36
|
-
canvas.line!(point, m, opt) if point
|
37
|
-
point = m
|
38
|
-
end
|
39
|
-
when :left_button_down
|
40
|
-
canvas.line!(m, m, opt)
|
41
|
-
point = m
|
42
|
-
when :left_button_up
|
43
|
-
point = nil
|
44
|
-
when :right_button_down
|
45
|
-
mask = canvas.flood_fill!(m, opt[:color])
|
46
|
-
end
|
47
|
-
window.show canvas
|
48
|
-
}
|
49
|
-
|
50
|
-
color_name = ''
|
51
|
-
while key = GUI.wait_key
|
52
|
-
next if key < 0 or key > 255
|
53
|
-
case key.chr
|
54
|
-
when "\e" # [esc] - exit
|
55
|
-
exit
|
56
|
-
when '1'..'9'
|
57
|
-
puts "change thickness to #{key.chr.to_i}."
|
58
|
-
opt[:thickness] = key.chr.to_i
|
59
|
-
when /[A-Za-z]/
|
60
|
-
color_name << key.chr
|
61
|
-
choice = colors.find_all{ |i| i =~ /\A#{color_name}/i }
|
62
|
-
if choice.size == 1
|
63
|
-
color,= choice
|
64
|
-
puts "change color to #{color}."
|
65
|
-
opt[:color] = CvColor::const_get(color)
|
66
|
-
end
|
67
|
-
color_name = '' if choice.size < 2
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# paint.rb
|
3
|
+
require "rubygems"
|
4
|
+
require "opencv"
|
5
|
+
|
6
|
+
include OpenCV
|
7
|
+
|
8
|
+
window = GUI::Window.new("free canvas")
|
9
|
+
canvas = CvMat.new(500, 500, CV_8U, 3).fill!(CvColor::White) # create white canvas
|
10
|
+
window.show canvas
|
11
|
+
|
12
|
+
colors = CvColor::constants.collect{ |i| i.to_s }
|
13
|
+
|
14
|
+
usage =<<USAGE
|
15
|
+
[mouse]
|
16
|
+
drag - draw
|
17
|
+
right button - fill by color
|
18
|
+
[keyborad]
|
19
|
+
1 to 9 - change thickness of line
|
20
|
+
type color name - change color
|
21
|
+
esc - exit
|
22
|
+
USAGE
|
23
|
+
puts usage
|
24
|
+
|
25
|
+
# drawing option
|
26
|
+
opt = {
|
27
|
+
:color => CvColor::Black,
|
28
|
+
:tickness => 1
|
29
|
+
}
|
30
|
+
|
31
|
+
point = nil
|
32
|
+
window.on_mouse{ |m|
|
33
|
+
case m.event
|
34
|
+
when :move
|
35
|
+
if m.left_button?
|
36
|
+
canvas.line!(point, m, opt) if point
|
37
|
+
point = m
|
38
|
+
end
|
39
|
+
when :left_button_down
|
40
|
+
canvas.line!(m, m, opt)
|
41
|
+
point = m
|
42
|
+
when :left_button_up
|
43
|
+
point = nil
|
44
|
+
when :right_button_down
|
45
|
+
mask = canvas.flood_fill!(m, opt[:color])
|
46
|
+
end
|
47
|
+
window.show canvas
|
48
|
+
}
|
49
|
+
|
50
|
+
color_name = ''
|
51
|
+
while key = GUI.wait_key
|
52
|
+
next if key < 0 or key > 255
|
53
|
+
case key.chr
|
54
|
+
when "\e" # [esc] - exit
|
55
|
+
exit
|
56
|
+
when '1'..'9'
|
57
|
+
puts "change thickness to #{key.chr.to_i}."
|
58
|
+
opt[:thickness] = key.chr.to_i
|
59
|
+
when /[A-Za-z]/
|
60
|
+
color_name << key.chr
|
61
|
+
choice = colors.find_all{ |i| i =~ /\A#{color_name}/i }
|
62
|
+
if choice.size == 1
|
63
|
+
color,= choice
|
64
|
+
puts "change color to #{color}."
|
65
|
+
opt[:color] = CvColor::const_get(color)
|
66
|
+
end
|
67
|
+
color_name = '' if choice.size < 2
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|