opencv 0.0.6
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.
- data/History.txt +5 -0
- data/License.txt +30 -0
- data/Manifest.txt +115 -0
- data/README.txt +47 -0
- data/Rakefile +34 -0
- data/examples/convexhull.rb +41 -0
- data/examples/face_detect.rb +25 -0
- data/examples/houghcircle.rb +23 -0
- data/examples/inpaint.png +0 -0
- data/examples/inpaint.rb +43 -0
- data/examples/paint.rb +72 -0
- data/examples/snake.rb +43 -0
- data/examples/stuff.jpg +0 -0
- data/ext/curve.cpp +103 -0
- data/ext/curve.h +34 -0
- data/ext/cvavgcomp.cpp +67 -0
- data/ext/cvavgcomp.h +39 -0
- data/ext/cvbox2d.cpp +114 -0
- data/ext/cvbox2d.h +53 -0
- data/ext/cvcapture.cpp +276 -0
- data/ext/cvcapture.h +54 -0
- data/ext/cvchain.cpp +184 -0
- data/ext/cvchain.h +43 -0
- data/ext/cvchaincode.cpp +49 -0
- data/ext/cvchaincode.h +43 -0
- data/ext/cvcircle32f.cpp +90 -0
- data/ext/cvcircle32f.h +53 -0
- data/ext/cvcondensation.cpp +230 -0
- data/ext/cvcondensation.h +49 -0
- data/ext/cvconnectedcomp.cpp +115 -0
- data/ext/cvconnectedcomp.h +46 -0
- data/ext/cvcontour.cpp +219 -0
- data/ext/cvcontour.h +47 -0
- data/ext/cvcontourtree.cpp +86 -0
- data/ext/cvcontourtree.h +41 -0
- data/ext/cvconvexitydefect.cpp +103 -0
- data/ext/cvconvexitydefect.h +42 -0
- data/ext/cverror.cpp +140 -0
- data/ext/cverror.h +79 -0
- data/ext/cvfont.cpp +173 -0
- data/ext/cvfont.h +56 -0
- data/ext/cvhaarclassifiercascade.cpp +159 -0
- data/ext/cvhaarclassifiercascade.h +41 -0
- data/ext/cvhistogram.cpp +200 -0
- data/ext/cvhistogram.h +51 -0
- data/ext/cvindex.cpp +73 -0
- data/ext/cvindex.h +40 -0
- data/ext/cvline.cpp +106 -0
- data/ext/cvline.h +52 -0
- data/ext/cvmat.cpp +4809 -0
- data/ext/cvmat.h +286 -0
- data/ext/cvmatnd.cpp +44 -0
- data/ext/cvmatnd.h +28 -0
- data/ext/cvmemstorage.cpp +64 -0
- data/ext/cvmemstorage.h +53 -0
- data/ext/cvmoments.cpp +204 -0
- data/ext/cvmoments.h +48 -0
- data/ext/cvpoint.cpp +229 -0
- data/ext/cvpoint.h +59 -0
- data/ext/cvpoint2d32f.cpp +213 -0
- data/ext/cvpoint2d32f.h +61 -0
- data/ext/cvpoint3d32f.cpp +245 -0
- data/ext/cvpoint3d32f.h +64 -0
- data/ext/cvrect.cpp +340 -0
- data/ext/cvrect.h +79 -0
- data/ext/cvscalar.cpp +227 -0
- data/ext/cvscalar.h +63 -0
- data/ext/cvseq.cpp +583 -0
- data/ext/cvseq.h +71 -0
- data/ext/cvset.cpp +63 -0
- data/ext/cvset.h +39 -0
- data/ext/cvsize.cpp +223 -0
- data/ext/cvsize.h +63 -0
- data/ext/cvsize2d32f.cpp +180 -0
- data/ext/cvsize2d32f.h +59 -0
- data/ext/cvslice.cpp +82 -0
- data/ext/cvslice.h +53 -0
- data/ext/cvsparsemat.cpp +44 -0
- data/ext/cvsparsemat.h +28 -0
- data/ext/cvtermcriteria.cpp +183 -0
- data/ext/cvtermcriteria.h +71 -0
- data/ext/cvtwopoints.cpp +98 -0
- data/ext/cvtwopoints.h +50 -0
- data/ext/cvvector.cpp +206 -0
- data/ext/cvvector.h +54 -0
- data/ext/cvvideowriter.cpp +116 -0
- data/ext/cvvideowriter.h +41 -0
- data/ext/extconf.rb +61 -0
- data/ext/gui.cpp +65 -0
- data/ext/gui.h +33 -0
- data/ext/iplconvkernel.cpp +177 -0
- data/ext/iplconvkernel.h +52 -0
- data/ext/iplimage.cpp +238 -0
- data/ext/iplimage.h +54 -0
- data/ext/mouseevent.cpp +184 -0
- data/ext/mouseevent.h +59 -0
- data/ext/opencv.cpp +481 -0
- data/ext/opencv.h +356 -0
- data/ext/point3dset.cpp +41 -0
- data/ext/point3dset.h +31 -0
- data/ext/pointset.cpp +238 -0
- data/ext/pointset.h +69 -0
- data/ext/trackbar.cpp +122 -0
- data/ext/trackbar.h +65 -0
- data/ext/window.cpp +368 -0
- data/ext/window.h +56 -0
- data/images/CvMat_sobel.png +0 -0
- data/images/CvMat_sub_rect.png +0 -0
- data/images/CvSeq_relationmap.png +0 -0
- data/images/face_detect_from_lena.jpg +0 -0
- data/lib/opencv.rb +3 -0
- data/lib/version.rb +3 -0
- data/setup/setup.cygwin.rb +120 -0
- data/setup/setup.mingw.rb +99 -0
- data/setup/setup.mswin32.rb +103 -0
- data/test/test_opencv.rb +4 -0
- metadata +191 -0
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
The BSD Liscense
|
2
|
+
|
3
|
+
Copyright (c) 2008, Masakazu Yonekura
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use of this software in source and binary forms, with or without modification, are
|
7
|
+
permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
* Redistributions of source code must retain the above
|
10
|
+
copyright notice, this list of conditions and the
|
11
|
+
following disclaimer.
|
12
|
+
|
13
|
+
* Redistributions in binary form must reproduce the above
|
14
|
+
copyright notice, this list of conditions and the
|
15
|
+
following disclaimer in the documentation and/or other
|
16
|
+
materials provided with the distribution.
|
17
|
+
|
18
|
+
* Neither the name of Masakazu Yonekura. nor the names of its
|
19
|
+
contributors may be used to endorse or promote products
|
20
|
+
derived from this software without specific prior
|
21
|
+
written permission of Masakazu Yonekura.
|
22
|
+
|
23
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
|
24
|
+
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
25
|
+
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
26
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
27
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
28
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
29
|
+
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
30
|
+
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
README.txt
|
4
|
+
License.txt
|
5
|
+
Rakefile
|
6
|
+
examples/convexhull.rb
|
7
|
+
examples/face_detect.rb
|
8
|
+
examples/houghcircle.rb
|
9
|
+
examples/inpaint.png
|
10
|
+
examples/inpaint.rb
|
11
|
+
examples/paint.rb
|
12
|
+
examples/snake.rb
|
13
|
+
examples/stuff.jpg
|
14
|
+
ext/curve.cpp
|
15
|
+
ext/curve.h
|
16
|
+
ext/cvavgcomp.cpp
|
17
|
+
ext/cvavgcomp.h
|
18
|
+
ext/cvbox2d.cpp
|
19
|
+
ext/cvbox2d.h
|
20
|
+
ext/cvcapture.cpp
|
21
|
+
ext/cvcapture.h
|
22
|
+
ext/cvchain.cpp
|
23
|
+
ext/cvchain.h
|
24
|
+
ext/cvchaincode.cpp
|
25
|
+
ext/cvchaincode.h
|
26
|
+
ext/cvcircle32f.cpp
|
27
|
+
ext/cvcircle32f.h
|
28
|
+
ext/cvcondensation.cpp
|
29
|
+
ext/cvcondensation.h
|
30
|
+
ext/cvconnectedcomp.cpp
|
31
|
+
ext/cvconnectedcomp.h
|
32
|
+
ext/cvcontour.cpp
|
33
|
+
ext/cvcontour.h
|
34
|
+
ext/cvcontourtree.cpp
|
35
|
+
ext/cvcontourtree.h
|
36
|
+
ext/cvconvexitydefect.cpp
|
37
|
+
ext/cvconvexitydefect.h
|
38
|
+
ext/cverror.cpp
|
39
|
+
ext/cverror.h
|
40
|
+
ext/cvfont.cpp
|
41
|
+
ext/cvfont.h
|
42
|
+
ext/cvhaarclassifiercascade.cpp
|
43
|
+
ext/cvhaarclassifiercascade.h
|
44
|
+
ext/cvhistogram.cpp
|
45
|
+
ext/cvhistogram.h
|
46
|
+
ext/cvindex.cpp
|
47
|
+
ext/cvindex.h
|
48
|
+
ext/cvline.cpp
|
49
|
+
ext/cvline.h
|
50
|
+
ext/cvmat.cpp
|
51
|
+
ext/cvmat.h
|
52
|
+
ext/cvmatnd.cpp
|
53
|
+
ext/cvmatnd.h
|
54
|
+
ext/cvmemstorage.cpp
|
55
|
+
ext/cvmemstorage.h
|
56
|
+
ext/cvmoments.cpp
|
57
|
+
ext/cvmoments.h
|
58
|
+
ext/cvpoint.cpp
|
59
|
+
ext/cvpoint.h
|
60
|
+
ext/cvpoint2d32f.cpp
|
61
|
+
ext/cvpoint2d32f.h
|
62
|
+
ext/cvpoint3d32f.cpp
|
63
|
+
ext/cvpoint3d32f.h
|
64
|
+
ext/cvrect.cpp
|
65
|
+
ext/cvrect.h
|
66
|
+
ext/cvscalar.cpp
|
67
|
+
ext/cvscalar.h
|
68
|
+
ext/cvseq.cpp
|
69
|
+
ext/cvseq.h
|
70
|
+
ext/cvset.cpp
|
71
|
+
ext/cvset.h
|
72
|
+
ext/cvsize.cpp
|
73
|
+
ext/cvsize.h
|
74
|
+
ext/cvsize2d32f.cpp
|
75
|
+
ext/cvsize2d32f.h
|
76
|
+
ext/cvslice.cpp
|
77
|
+
ext/cvslice.h
|
78
|
+
ext/cvsparsemat.cpp
|
79
|
+
ext/cvsparsemat.h
|
80
|
+
ext/cvtermcriteria.cpp
|
81
|
+
ext/cvtermcriteria.h
|
82
|
+
ext/cvtwopoints.cpp
|
83
|
+
ext/cvtwopoints.h
|
84
|
+
ext/cvvector.cpp
|
85
|
+
ext/cvvector.h
|
86
|
+
ext/cvvideowriter.cpp
|
87
|
+
ext/cvvideowriter.h
|
88
|
+
ext/extconf.rb
|
89
|
+
ext/gui.cpp
|
90
|
+
ext/gui.h
|
91
|
+
ext/iplconvkernel.cpp
|
92
|
+
ext/iplconvkernel.h
|
93
|
+
ext/iplimage.cpp
|
94
|
+
ext/iplimage.h
|
95
|
+
ext/mouseevent.cpp
|
96
|
+
ext/mouseevent.h
|
97
|
+
ext/opencv.cpp
|
98
|
+
ext/opencv.h
|
99
|
+
ext/point3dset.cpp
|
100
|
+
ext/point3dset.h
|
101
|
+
ext/pointset.cpp
|
102
|
+
ext/pointset.h
|
103
|
+
ext/trackbar.cpp
|
104
|
+
ext/trackbar.h
|
105
|
+
ext/window.cpp
|
106
|
+
ext/window.h
|
107
|
+
images/CvMat_sobel.png
|
108
|
+
images/CvMat_sub_rect.png
|
109
|
+
images/CvSeq_relationmap.png
|
110
|
+
images/face_detect_from_lena.jpg
|
111
|
+
lib/opencv.rb
|
112
|
+
lib/version.rb
|
113
|
+
setup/setup.cygwin.rb
|
114
|
+
setup/setup.mingw.rb
|
115
|
+
setup/setup.mswin32.rb
|
data/README.txt
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
= opencv
|
2
|
+
|
3
|
+
OpenCV Sourceforge Project
|
4
|
+
http://sourceforge.net/projects/opencvlibrary/
|
5
|
+
|
6
|
+
Ruby/OpenCV Author's Web Page
|
7
|
+
http://blueruby.mydns.jp/opencv
|
8
|
+
|
9
|
+
== DESCRIPTION:
|
10
|
+
|
11
|
+
OpenCV Ruby Wrapper
|
12
|
+
|
13
|
+
== FEATURES/PROBLEMS:
|
14
|
+
|
15
|
+
* First release rubygems, Some OpenCV function wrapped.
|
16
|
+
|
17
|
+
== SYNOPSIS:
|
18
|
+
|
19
|
+
# Show image via GUI Window.
|
20
|
+
|
21
|
+
require "rubygems"
|
22
|
+
gem "opencv"
|
23
|
+
require "opencv"
|
24
|
+
|
25
|
+
image = OpenCV::IplImage.load("sample.jpg")
|
26
|
+
window = OpenCV::GUI::Window.new("preview")
|
27
|
+
window.show(image)
|
28
|
+
OpenCV::GUI::wait_key
|
29
|
+
|
30
|
+
# other sample code, see examples/*.rb
|
31
|
+
|
32
|
+
== REQUIREMENTS:
|
33
|
+
|
34
|
+
* OpenCV 1.0 or later.
|
35
|
+
http://sourceforge.net/projects/opencvlibrary/
|
36
|
+
* ffcall (optional)
|
37
|
+
http://www.haible.de/bruno/packages-ffcall.html
|
38
|
+
|
39
|
+
== INSTALL:
|
40
|
+
|
41
|
+
gem install opencv
|
42
|
+
|
43
|
+
== LICENSE:
|
44
|
+
|
45
|
+
The BSD Liscense
|
46
|
+
|
47
|
+
see LICENSE.txt
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/version'
|
6
|
+
|
7
|
+
Hoe.new('opencv', OpenCV::VERSION) do |p|
|
8
|
+
p.author = ['Masakazu Yonekura']
|
9
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
10
|
+
p.description = <<EOF
|
11
|
+
OpenCV wrapper for Ruby
|
12
|
+
EOF
|
13
|
+
p.rubyforge_name = 'opencv'
|
14
|
+
p.developer('lsxi', 'masakazu.yonekura@gmail.com')
|
15
|
+
p.email = ['masakazu.yonekura@gmail.com']
|
16
|
+
|
17
|
+
p.need_tar = false
|
18
|
+
p.need_zip = false
|
19
|
+
# p.rdoc_pattern =
|
20
|
+
# p.remote_rdoc_dir =
|
21
|
+
# p.rsync =
|
22
|
+
p.spec_extras = {
|
23
|
+
:extensions => %w{ext/extconf.rb}
|
24
|
+
}
|
25
|
+
p.summary = 'OpenCV wrapper for Ruby.'
|
26
|
+
# p.test_globs = 'spec/**/*_spec.rb'
|
27
|
+
p.clean_globs |= ['*.o']
|
28
|
+
|
29
|
+
p.url = 'http://blueruby.mydns.jp/opencv'
|
30
|
+
|
31
|
+
p.extra_deps << ['hoe']
|
32
|
+
end
|
33
|
+
|
34
|
+
# vim: syntax=Ruby
|
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
# convexhull.rb
|
3
|
+
gem "opencv"
|
4
|
+
require "opencv"
|
5
|
+
require "pp"
|
6
|
+
include OpenCV
|
7
|
+
|
8
|
+
window = GUI::Window.new("convexhull")
|
9
|
+
pp CvCapture::INTERFACE
|
10
|
+
capture = CvCapture::open
|
11
|
+
|
12
|
+
accuracy = 0.1
|
13
|
+
t = window.set_trackbar("accuracy", 100, 1){|v|
|
14
|
+
accuracy = 0.1 * v
|
15
|
+
}
|
16
|
+
|
17
|
+
while true
|
18
|
+
key = GUI::wait_key(1)
|
19
|
+
image = capture.query
|
20
|
+
gray = image.BGR2GRAY
|
21
|
+
bin = gray.threshold_binary(0x44, 0xFF)
|
22
|
+
contours = bin.find_contours
|
23
|
+
while contours
|
24
|
+
image.poly_line! contours.approx(:accuracy => accuracy), :color => CvScalar::Red
|
25
|
+
contours.convexity_defects.each{|cd|
|
26
|
+
image.circle! cd.start, 1, :color => CvScalar::Blue
|
27
|
+
image.circle! cd.end, 1, :color => CvScalar::Blue
|
28
|
+
image.circle! cd.depth_point, 1, :color => CvScalar::Blue
|
29
|
+
}
|
30
|
+
|
31
|
+
contours = contours.h_next
|
32
|
+
end
|
33
|
+
#pts = gray.good_features_to_track(0.01, 10)
|
34
|
+
#puts pts.length
|
35
|
+
window.show image
|
36
|
+
next unless key
|
37
|
+
case key.chr
|
38
|
+
when "\e"
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
# face_detect.rb
|
3
|
+
require "rubygems"
|
4
|
+
gem "opencv"
|
5
|
+
require "opencv"
|
6
|
+
|
7
|
+
include OpenCV
|
8
|
+
|
9
|
+
window = GUI::Window.new("face detect")
|
10
|
+
capture = CvCapture.open
|
11
|
+
detector = CvHaarClassifierCascade::load("C:/Program Files/OpenCV/data/haarcascades/haarcascade_frontalface_alt.xml")
|
12
|
+
|
13
|
+
while true
|
14
|
+
key = GUI::wait_key(1)
|
15
|
+
image = capture.query
|
16
|
+
detector.detect_objects(image){|i|
|
17
|
+
image.rectangle! i.top_left, i.bottom_right, :color => CvColor::Red
|
18
|
+
}
|
19
|
+
window.show image
|
20
|
+
next unless key
|
21
|
+
case key.chr
|
22
|
+
when "\e"
|
23
|
+
exit
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
# houghcircle.rb
|
3
|
+
require "rubygems"
|
4
|
+
gem "opencv"
|
5
|
+
require "opencv"
|
6
|
+
include OpenCV
|
7
|
+
|
8
|
+
original_window = GUI::Window.new "original"
|
9
|
+
hough_window = GUI::Window.new "hough circles"
|
10
|
+
|
11
|
+
image = IplImage::load "stuff.jpg"
|
12
|
+
gray = image.BGR2GRAY
|
13
|
+
|
14
|
+
result = image.clone
|
15
|
+
original_window.show image
|
16
|
+
detect = gray.hough_circles_gradient(2.0, 10, 200, 50)
|
17
|
+
puts detect.size
|
18
|
+
detect.each{|circle|
|
19
|
+
puts "#{circle.center.x},#{circle.center.y} - #{circle.radius}"
|
20
|
+
result.circle! circle.center, circle.radius, :color => CvColor::Red, :thickness => 3
|
21
|
+
}
|
22
|
+
hough_window.show result
|
23
|
+
GUI::wait_key
|
Binary file
|
data/examples/inpaint.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
# inpaint.rb
|
3
|
+
require "rubygems"
|
4
|
+
gem "opencv"
|
5
|
+
require "opencv"
|
6
|
+
|
7
|
+
include OpenCV
|
8
|
+
|
9
|
+
owindow = GUI::Window.new "original"
|
10
|
+
mwindow = GUI::Window.new "mask"
|
11
|
+
iwindow = GUI::Window.new "inpaint"
|
12
|
+
|
13
|
+
image = IplImage::load "inpaint.png"
|
14
|
+
b, g, r = image.split
|
15
|
+
original_mask = r.threshold_binary_inverse(0x00, 0xFF) & b.threshold_binary_inverse(0x00, 0xFF)
|
16
|
+
mask = original_mask.copy
|
17
|
+
|
18
|
+
num_dilate = 3
|
19
|
+
radius = 5
|
20
|
+
dilate_bar = mwindow.set_trackbar("dilate", 10, num_dilate){|v|
|
21
|
+
num_dilate = v
|
22
|
+
mask = original_mask.dilate(nil, num_dilate)
|
23
|
+
mwindow.show mask
|
24
|
+
}
|
25
|
+
|
26
|
+
radius_bar = mwindow.set_trackbar("radius", 30, radius){|v|
|
27
|
+
radius = v
|
28
|
+
}
|
29
|
+
|
30
|
+
owindow.show image
|
31
|
+
mwindow.show mask
|
32
|
+
|
33
|
+
while key = GUI::wait_key
|
34
|
+
case key.chr
|
35
|
+
when "\e" # esc
|
36
|
+
exit
|
37
|
+
when "n"
|
38
|
+
iwindow.show image.inpaint_ns(mask, radius)
|
39
|
+
when "t"
|
40
|
+
iwindow.show image.inpaint_telea(mask, radius)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
data/examples/paint.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
# paint.rb
|
3
|
+
require "rubygems"
|
4
|
+
gem "opencv"
|
5
|
+
require "opencv"
|
6
|
+
|
7
|
+
include OpenCV
|
8
|
+
|
9
|
+
window = GUI::Window.new("free canvas")
|
10
|
+
canvas = CvMat.new(500, 500, 0, 3).fill!(0xFF) # create white canvas
|
11
|
+
window.show canvas
|
12
|
+
|
13
|
+
colors = CvColor::constants.collect{|i| i.to_s }
|
14
|
+
|
15
|
+
usage =<<USAGE
|
16
|
+
[mouse]
|
17
|
+
drag - draw
|
18
|
+
right button - fill by color
|
19
|
+
[keyborad]
|
20
|
+
1 to 9 - change thickness of line
|
21
|
+
type color name - change color
|
22
|
+
esc - exit
|
23
|
+
USAGE
|
24
|
+
puts usage
|
25
|
+
|
26
|
+
point = nil
|
27
|
+
|
28
|
+
# drawing option
|
29
|
+
opt = {
|
30
|
+
:color => CvColor::Black,
|
31
|
+
:tickness => 1
|
32
|
+
}
|
33
|
+
|
34
|
+
window.on_mouse{|m|
|
35
|
+
case m.event
|
36
|
+
when :move
|
37
|
+
if m.left_button?
|
38
|
+
canvas.line!(point, m, opt) if point
|
39
|
+
point = m
|
40
|
+
end
|
41
|
+
when :left_button_down
|
42
|
+
canvas.line!(m, m, opt)
|
43
|
+
point = m
|
44
|
+
when :left_button_up
|
45
|
+
point = nil
|
46
|
+
when :right_button_down
|
47
|
+
mask = canvas.flood_fill!(m, opt[:color])
|
48
|
+
end
|
49
|
+
window.show canvas
|
50
|
+
}
|
51
|
+
|
52
|
+
color_name = ''
|
53
|
+
while key = GUI.wait_key
|
54
|
+
next if key < 0
|
55
|
+
case key.chr
|
56
|
+
when "\e" # [esc] - exit
|
57
|
+
exit
|
58
|
+
when '1'..'9'
|
59
|
+
puts "change thickness to #{key.chr.to_i}."
|
60
|
+
opt[:thickness] = key.chr.to_i
|
61
|
+
else
|
62
|
+
color_name << key.chr
|
63
|
+
choice = colors.find_all{|i| i =~ /\A#{color_name}/i}
|
64
|
+
if choice.size == 1
|
65
|
+
color,= choice
|
66
|
+
puts "change color to #{color}."
|
67
|
+
opt[:color] = CvColor::const_get(color)
|
68
|
+
end
|
69
|
+
color_name = '' if choice.length < 2
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|