afeld-opencv 0.0.8
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/.gitignore +23 -0
- data/Gemfile +6 -0
- data/History.txt +5 -0
- data/License.txt +30 -0
- data/Manifest.txt +217 -0
- data/README.rdoc +161 -0
- data/Rakefile +52 -0
- data/examples/alpha_blend.rb +21 -0
- data/examples/box.png +0 -0
- data/examples/box_in_scene.png +0 -0
- data/examples/contours/bitmap-contours-with-labels.png +0 -0
- data/examples/contours/bitmap-contours.png +0 -0
- data/examples/contours/bounding-box-detect-canny.rb +62 -0
- data/examples/contours/contour_retrieval_modes.rb +139 -0
- data/examples/contours/rotated-boxes.jpg +0 -0
- data/examples/convexhull.rb +47 -0
- data/examples/face_detect.rb +20 -0
- data/examples/find_obj.rb +169 -0
- data/examples/houghcircle.rb +22 -0
- data/examples/inpaint.png +0 -0
- data/examples/inpaint.rb +57 -0
- data/examples/lenna-rotated.jpg +0 -0
- data/examples/lenna.jpg +0 -0
- data/examples/match_kdtree.rb +88 -0
- data/examples/paint.rb +70 -0
- data/examples/snake.rb +43 -0
- data/examples/stuff.jpg +0 -0
- data/examples/tiffany.jpg +0 -0
- data/ext/opencv/curve.cpp +112 -0
- data/ext/opencv/curve.h +34 -0
- data/ext/opencv/cvavgcomp.cpp +67 -0
- data/ext/opencv/cvavgcomp.h +39 -0
- data/ext/opencv/cvbox2d.cpp +197 -0
- data/ext/opencv/cvbox2d.h +61 -0
- data/ext/opencv/cvcapture.cpp +499 -0
- data/ext/opencv/cvcapture.h +72 -0
- data/ext/opencv/cvchain.cpp +230 -0
- data/ext/opencv/cvchain.h +46 -0
- data/ext/opencv/cvcircle32f.cpp +116 -0
- data/ext/opencv/cvcircle32f.h +52 -0
- data/ext/opencv/cvcondensation.cpp +282 -0
- data/ext/opencv/cvcondensation.h +49 -0
- data/ext/opencv/cvconnectedcomp.cpp +143 -0
- data/ext/opencv/cvconnectedcomp.h +49 -0
- data/ext/opencv/cvcontour.cpp +297 -0
- data/ext/opencv/cvcontour.h +48 -0
- data/ext/opencv/cvcontourtree.cpp +91 -0
- data/ext/opencv/cvcontourtree.h +41 -0
- data/ext/opencv/cvconvexitydefect.cpp +103 -0
- data/ext/opencv/cvconvexitydefect.h +42 -0
- data/ext/opencv/cverror.cpp +159 -0
- data/ext/opencv/cverror.h +28 -0
- data/ext/opencv/cvfeaturetree.cpp +125 -0
- data/ext/opencv/cvfeaturetree.h +55 -0
- data/ext/opencv/cvfont.cpp +208 -0
- data/ext/opencv/cvfont.h +64 -0
- data/ext/opencv/cvhaarclassifiercascade.cpp +168 -0
- data/ext/opencv/cvhaarclassifiercascade.h +39 -0
- data/ext/opencv/cvhistogram.cpp +546 -0
- data/ext/opencv/cvhistogram.h +73 -0
- data/ext/opencv/cvhumoments.cpp +139 -0
- data/ext/opencv/cvhumoments.h +51 -0
- data/ext/opencv/cvline.cpp +154 -0
- data/ext/opencv/cvline.h +54 -0
- data/ext/opencv/cvmat.cpp +5627 -0
- data/ext/opencv/cvmat.h +280 -0
- data/ext/opencv/cvmatnd.cpp +44 -0
- data/ext/opencv/cvmatnd.h +28 -0
- data/ext/opencv/cvmemstorage.cpp +68 -0
- data/ext/opencv/cvmemstorage.h +53 -0
- data/ext/opencv/cvmoments.cpp +287 -0
- data/ext/opencv/cvmoments.h +75 -0
- data/ext/opencv/cvpoint.cpp +228 -0
- data/ext/opencv/cvpoint.h +64 -0
- data/ext/opencv/cvpoint2d32f.cpp +211 -0
- data/ext/opencv/cvpoint2d32f.h +63 -0
- data/ext/opencv/cvpoint3d32f.cpp +246 -0
- data/ext/opencv/cvpoint3d32f.h +66 -0
- data/ext/opencv/cvrect.cpp +333 -0
- data/ext/opencv/cvrect.h +79 -0
- data/ext/opencv/cvscalar.cpp +236 -0
- data/ext/opencv/cvscalar.h +71 -0
- data/ext/opencv/cvseq.cpp +599 -0
- data/ext/opencv/cvseq.h +72 -0
- data/ext/opencv/cvsize.cpp +221 -0
- data/ext/opencv/cvsize.h +65 -0
- data/ext/opencv/cvsize2d32f.cpp +209 -0
- data/ext/opencv/cvsize2d32f.h +64 -0
- data/ext/opencv/cvslice.cpp +120 -0
- data/ext/opencv/cvslice.h +61 -0
- data/ext/opencv/cvsparsemat.cpp +44 -0
- data/ext/opencv/cvsparsemat.h +28 -0
- data/ext/opencv/cvsurfparams.cpp +199 -0
- data/ext/opencv/cvsurfparams.h +58 -0
- data/ext/opencv/cvsurfpoint.cpp +223 -0
- data/ext/opencv/cvsurfpoint.h +52 -0
- data/ext/opencv/cvtermcriteria.cpp +192 -0
- data/ext/opencv/cvtermcriteria.h +71 -0
- data/ext/opencv/cvtwopoints.cpp +116 -0
- data/ext/opencv/cvtwopoints.h +51 -0
- data/ext/opencv/cvutils.cpp +194 -0
- data/ext/opencv/cvutils.h +29 -0
- data/ext/opencv/cvvideowriter.cpp +137 -0
- data/ext/opencv/cvvideowriter.h +43 -0
- data/ext/opencv/gui.cpp +68 -0
- data/ext/opencv/gui.h +30 -0
- data/ext/opencv/iplconvkernel.cpp +192 -0
- data/ext/opencv/iplconvkernel.h +71 -0
- data/ext/opencv/iplimage.cpp +576 -0
- data/ext/opencv/iplimage.h +70 -0
- data/ext/opencv/lib/opencv.rb +3 -0
- data/ext/opencv/lib/opencv/psyched_yaml.rb +22 -0
- data/ext/opencv/lib/opencv/version.rb +3 -0
- data/ext/opencv/mouseevent.cpp +181 -0
- data/ext/opencv/mouseevent.h +56 -0
- data/ext/opencv/opencv.cpp +710 -0
- data/ext/opencv/opencv.h +400 -0
- data/ext/opencv/pointset.cpp +284 -0
- data/ext/opencv/pointset.h +69 -0
- data/ext/opencv/trackbar.cpp +121 -0
- data/ext/opencv/trackbar.h +69 -0
- data/ext/opencv/window.cpp +357 -0
- data/ext/opencv/window.h +66 -0
- data/extconf.rb +65 -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/test/helper.rb +146 -0
- data/test/runner.rb +30 -0
- data/test/samples/airplane.jpg +0 -0
- data/test/samples/baboon.jpg +0 -0
- data/test/samples/baboon200.jpg +0 -0
- data/test/samples/baboon200_rotated.jpg +0 -0
- data/test/samples/blank0.jpg +0 -0
- data/test/samples/blank1.jpg +0 -0
- data/test/samples/blank2.jpg +0 -0
- data/test/samples/blank3.jpg +0 -0
- data/test/samples/blank4.jpg +0 -0
- data/test/samples/blank5.jpg +0 -0
- data/test/samples/blank6.jpg +0 -0
- data/test/samples/blank7.jpg +0 -0
- data/test/samples/blank8.jpg +0 -0
- data/test/samples/blank9.jpg +0 -0
- data/test/samples/cat.jpg +0 -0
- data/test/samples/contours.jpg +0 -0
- data/test/samples/fruits.jpg +0 -0
- data/test/samples/haarcascade_frontalface_alt.xml.gz +0 -0
- data/test/samples/inpaint-mask.bmp +0 -0
- data/test/samples/lena-256x256.jpg +0 -0
- data/test/samples/lena-32x32.jpg +0 -0
- data/test/samples/lena-eyes.jpg +0 -0
- data/test/samples/lena-inpaint.jpg +0 -0
- data/test/samples/lena.jpg +0 -0
- data/test/samples/lines.jpg +0 -0
- data/test/samples/messy0.jpg +0 -0
- data/test/samples/messy1.jpg +0 -0
- data/test/samples/movie_sample.avi +0 -0
- data/test/samples/one_way_train_0000.jpg +0 -0
- data/test/samples/one_way_train_0001.jpg +0 -0
- data/test/samples/partially_blank0.jpg +0 -0
- data/test/samples/partially_blank1.jpg +0 -0
- data/test/samples/smooth0.jpg +0 -0
- data/test/samples/smooth1.jpg +0 -0
- data/test/samples/smooth2.jpg +0 -0
- data/test/samples/smooth3.jpg +0 -0
- data/test/samples/smooth4.jpg +0 -0
- data/test/samples/smooth5.jpg +0 -0
- data/test/samples/smooth6.jpg +0 -0
- data/test/samples/str-cv-rotated.jpg +0 -0
- data/test/samples/str-cv.jpg +0 -0
- data/test/samples/str-ov.jpg +0 -0
- data/test/samples/stuff.jpg +0 -0
- data/test/test_curve.rb +43 -0
- data/test/test_cvavgcomp.rb +24 -0
- data/test/test_cvbox2d.rb +76 -0
- data/test/test_cvcapture.rb +183 -0
- data/test/test_cvchain.rb +108 -0
- data/test/test_cvcircle32f.rb +41 -0
- data/test/test_cvconnectedcomp.rb +61 -0
- data/test/test_cvcontour.rb +150 -0
- data/test/test_cvcontourtree.rb +43 -0
- data/test/test_cverror.rb +50 -0
- data/test/test_cvfeaturetree.rb +65 -0
- data/test/test_cvfont.rb +58 -0
- data/test/test_cvhaarclassifiercascade.rb +63 -0
- data/test/test_cvhistogram.rb +271 -0
- data/test/test_cvhumoments.rb +83 -0
- data/test/test_cvline.rb +50 -0
- data/test/test_cvmat.rb +2752 -0
- data/test/test_cvmat_drawing.rb +318 -0
- data/test/test_cvmat_dxt.rb +147 -0
- data/test/test_cvmat_imageprocessing.rb +1943 -0
- data/test/test_cvmoments.rb +180 -0
- data/test/test_cvpoint.rb +75 -0
- data/test/test_cvpoint2d32f.rb +75 -0
- data/test/test_cvpoint3d32f.rb +93 -0
- data/test/test_cvrect.rb +144 -0
- data/test/test_cvscalar.rb +113 -0
- data/test/test_cvseq.rb +295 -0
- data/test/test_cvsize.rb +75 -0
- data/test/test_cvsize2d32f.rb +75 -0
- data/test/test_cvslice.rb +31 -0
- data/test/test_cvsurfparams.rb +57 -0
- data/test/test_cvsurfpoint.rb +66 -0
- data/test/test_cvtermcriteria.rb +56 -0
- data/test/test_cvtwopoints.rb +40 -0
- data/test/test_cvvideowriter.rb +58 -0
- data/test/test_iplconvkernel.rb +54 -0
- data/test/test_iplimage.rb +156 -0
- data/test/test_mouseevent.rb +17 -0
- data/test/test_opencv.rb +340 -0
- data/test/test_pointset.rb +130 -0
- data/test/test_preliminary.rb +130 -0
- data/test/test_trackbar.rb +47 -0
- data/test/test_window.rb +115 -0
- metadata +399 -0
@@ -0,0 +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
|
Binary file
|
data/examples/inpaint.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# inpaint.rb
|
3
|
+
require "rubygems"
|
4
|
+
require "opencv"
|
5
|
+
include OpenCV
|
6
|
+
|
7
|
+
puts <<EOS
|
8
|
+
Inpainting sample
|
9
|
+
|
10
|
+
Usage:
|
11
|
+
'dilate' bar - Adjust mask to inpaint (Non-black areas indicate the area that needs to be inpainted).
|
12
|
+
'radius' bar - Adjust radius of a circular neighborhood of each point inpainted.
|
13
|
+
'n' key - Inpaint using Navier-Stokes based method
|
14
|
+
't' key - Inpaint using Alexandru Telea's method
|
15
|
+
'c' key - Clear the inpaint window
|
16
|
+
'ESC' key - exit"
|
17
|
+
EOS
|
18
|
+
|
19
|
+
owindow = GUI::Window.new('original')
|
20
|
+
mwindow = GUI::Window.new('mask')
|
21
|
+
iwindow = GUI::Window.new('inpaint')
|
22
|
+
|
23
|
+
image = IplImage::load('inpaint.png')
|
24
|
+
noimage = image.zero
|
25
|
+
b, g, r = image.split
|
26
|
+
original_mask = r.threshold(0x00, 0xFF, CV_THRESH_BINARY_INV) & b.threshold(0x00, 0xFF, CV_THRESH_BINARY_INV)
|
27
|
+
mask = original_mask.copy
|
28
|
+
|
29
|
+
num_dilate = 3
|
30
|
+
mwindow.set_trackbar("dilate", 10, num_dilate) { |v|
|
31
|
+
num_dilate = v
|
32
|
+
mask = original_mask.dilate(nil, num_dilate)
|
33
|
+
mwindow.show mask
|
34
|
+
}
|
35
|
+
|
36
|
+
radius = 5
|
37
|
+
mwindow.set_trackbar("radius", 10, radius) { |v|
|
38
|
+
radius = v
|
39
|
+
}
|
40
|
+
|
41
|
+
owindow.show image
|
42
|
+
mwindow.show mask
|
43
|
+
iwindow.show noimage
|
44
|
+
|
45
|
+
while key = GUI::wait_key
|
46
|
+
case key.chr
|
47
|
+
when "\e" # esc
|
48
|
+
exit
|
49
|
+
when "n"
|
50
|
+
iwindow.show image.inpaint(:ns, mask, radius)
|
51
|
+
when "t"
|
52
|
+
iwindow.show image.inpaint(:telea, mask, radius)
|
53
|
+
when "c"
|
54
|
+
iwindow.show noimage
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
Binary file
|
data/examples/lenna.jpg
ADDED
Binary file
|
@@ -0,0 +1,88 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- mode: ruby; coding: utf-8-unix -*-
|
3
|
+
|
4
|
+
# A sample of matching SURF feature points using kd-tree
|
5
|
+
# See http://tech.groups.yahoo.com/group/OpenCV/message/62318
|
6
|
+
|
7
|
+
require 'opencv'
|
8
|
+
include OpenCV
|
9
|
+
|
10
|
+
USE_EXTENDED_DESCRIPTOR = true
|
11
|
+
THRESHOLD = 1500
|
12
|
+
DESCRIPTOR_SIZE = USE_EXTENDED_DESCRIPTOR ? 128 : 64
|
13
|
+
|
14
|
+
img1 = CvMat.load('lenna.jpg', CV_LOAD_IMAGE_GRAYSCALE)
|
15
|
+
img2 = CvMat.load('lenna-rotated.jpg', CV_LOAD_IMAGE_GRAYSCALE)
|
16
|
+
|
17
|
+
puts 'Extracting features from img1 using SURF...'
|
18
|
+
param = CvSURFParams.new(THRESHOLD, USE_EXTENDED_DESCRIPTOR)
|
19
|
+
kp1, desc1 = img1.extract_surf(param)
|
20
|
+
puts "found #{kp1.size} keypoints from img1"
|
21
|
+
|
22
|
+
puts 'Extracting features from img2 using SURF...'
|
23
|
+
kp2, desc2 = img2.extract_surf(param)
|
24
|
+
puts "found #{kp2.size} keypoints from img2"
|
25
|
+
|
26
|
+
puts 'Matching keypoints...'
|
27
|
+
desc1mat = CvMat.new(kp1.size, DESCRIPTOR_SIZE, :cv32f, 1)
|
28
|
+
desc2mat = CvMat.new(kp2.size, DESCRIPTOR_SIZE, :cv32f, 1)
|
29
|
+
desc1.each_with_index { |desc, i|
|
30
|
+
desc.each_with_index { |d, j|
|
31
|
+
desc1mat[i, j] = CvScalar.new(d)
|
32
|
+
}
|
33
|
+
}
|
34
|
+
desc2.each_with_index { |desc, i|
|
35
|
+
desc.each_with_index { |d, j|
|
36
|
+
desc2mat[i, j] = CvScalar.new(d)
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
feature_tree = CvFeatureTree.new(desc1mat)
|
41
|
+
results, distances = feature_tree.find_features(desc2mat, 1, 250)
|
42
|
+
|
43
|
+
reverse_lookup = []
|
44
|
+
reverse_lookup_dist = []
|
45
|
+
kp1.size.times { |i|
|
46
|
+
reverse_lookup << -1
|
47
|
+
reverse_lookup_dist << Float::MAX
|
48
|
+
}
|
49
|
+
|
50
|
+
match_count = 0
|
51
|
+
kp2.size.times { |j|
|
52
|
+
i = results[j][0].to_i
|
53
|
+
d = distances[j][0]
|
54
|
+
if (d < reverse_lookup_dist[i])
|
55
|
+
match_count += 1 if reverse_lookup_dist[i] == Float::MAX
|
56
|
+
reverse_lookup[i] = j
|
57
|
+
reverse_lookup_dist[i] = d
|
58
|
+
end
|
59
|
+
}
|
60
|
+
puts "found #{match_count} putative correspondences"
|
61
|
+
|
62
|
+
points1 = []
|
63
|
+
points2 = []
|
64
|
+
kp2.size.times { |j|
|
65
|
+
i = results[j][0].to_i
|
66
|
+
if (j == reverse_lookup[i])
|
67
|
+
points1 << kp1[i].pt
|
68
|
+
points2 << kp2[j].pt
|
69
|
+
end
|
70
|
+
}
|
71
|
+
|
72
|
+
width = img1.cols + img2.cols
|
73
|
+
height = (img1.rows > img2.rows) ? img1.rows : img2.rows
|
74
|
+
correspond = IplImage.new(width, height, :cv8u, 1);
|
75
|
+
correspond.set_roi(CvRect.new(0, 0, img1.cols, img1.rows))
|
76
|
+
img1.copy(correspond)
|
77
|
+
correspond.set_roi(CvRect.new(img1.cols, 0, img1.cols + img2.cols, img2.rows))
|
78
|
+
img2.copy(correspond)
|
79
|
+
correspond.reset_roi
|
80
|
+
|
81
|
+
points1.zip(points2) { |pt1, pt2|
|
82
|
+
pt2.x += img1.cols
|
83
|
+
correspond.line!(pt1, pt2, :color => CvColor::White)
|
84
|
+
}
|
85
|
+
|
86
|
+
GUI::Window.new('Object Correspond').show correspond
|
87
|
+
GUI::wait_key
|
88
|
+
|
data/examples/paint.rb
ADDED
@@ -0,0 +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
|
+
|
data/examples/snake.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# snake.rb
|
3
|
+
require "rubygems"
|
4
|
+
require "opencv"
|
5
|
+
include OpenCV
|
6
|
+
|
7
|
+
puts <<USAGE
|
8
|
+
usage:
|
9
|
+
left-click: set a point
|
10
|
+
right-click: do snake
|
11
|
+
USAGE
|
12
|
+
|
13
|
+
window = GUI::Window.new "snake demo"
|
14
|
+
image = CvMat.new(256, 256, :cv8u, 1).clear!
|
15
|
+
image.circle!(CvPoint.new(128,128), 40, :color => CvColor::White, :thickness => -1)
|
16
|
+
display = image.GRAY2BGR
|
17
|
+
|
18
|
+
window.show display
|
19
|
+
|
20
|
+
points = []
|
21
|
+
|
22
|
+
window.on_mouse{|mouse|
|
23
|
+
case mouse.event
|
24
|
+
when :left_button_down
|
25
|
+
display.circle!(mouse, 1, :color => CvColor::Red, :thickness => 2)
|
26
|
+
puts "set point (#{mouse.x},#{mouse.y})"
|
27
|
+
points << CvPoint.new(mouse.x, mouse.y)
|
28
|
+
window.show display
|
29
|
+
when :right_button_down
|
30
|
+
if points.length < 3
|
31
|
+
puts "please set more point!"
|
32
|
+
next
|
33
|
+
end
|
34
|
+
snake_points = image.snake_image(points, 1.0, 0.5, 1.5, CvSize.new(3, 3), 100)
|
35
|
+
display = image.GRAY2BGR
|
36
|
+
display.poly_line!([snake_points], :color => CvColor::Red, :is_closed => true, :thickness => 2)
|
37
|
+
window.show display
|
38
|
+
points.clear
|
39
|
+
end
|
40
|
+
}
|
41
|
+
|
42
|
+
GUI::wait_key
|
43
|
+
|
data/examples/stuff.jpg
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,112 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
curve.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "curve.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::Curve
|
13
|
+
*
|
14
|
+
* Curve sequence.
|
15
|
+
*/
|
16
|
+
__NAMESPACE_BEGIN_OPENCV
|
17
|
+
__NAMESPACE_BEGIN_CURVE
|
18
|
+
|
19
|
+
VALUE module;
|
20
|
+
|
21
|
+
VALUE
|
22
|
+
rb_module()
|
23
|
+
{
|
24
|
+
return module;
|
25
|
+
}
|
26
|
+
|
27
|
+
void
|
28
|
+
define_ruby_module()
|
29
|
+
{
|
30
|
+
if (module)
|
31
|
+
return;
|
32
|
+
/*
|
33
|
+
* opencv = rb_define_module("OpenCV");
|
34
|
+
*
|
35
|
+
* note: this comment is used by rdoc.
|
36
|
+
*/
|
37
|
+
VALUE opencv = rb_module_opencv();
|
38
|
+
module = rb_define_module_under(opencv, "Curve");
|
39
|
+
rb_define_method(module, "closed?", RUBY_METHOD_FUNC(rb_closed_q), 0);
|
40
|
+
rb_define_method(module, "convex?", RUBY_METHOD_FUNC(rb_convex_q), 0);
|
41
|
+
rb_define_method(module, "hole?", RUBY_METHOD_FUNC(rb_hole_q), 0);
|
42
|
+
rb_define_method(module, "simple?", RUBY_METHOD_FUNC(rb_simple_q), 0);
|
43
|
+
rb_define_method(module, "arc_length", RUBY_METHOD_FUNC(rb_arc_length), -1);
|
44
|
+
}
|
45
|
+
|
46
|
+
/*
|
47
|
+
* If curve is closed, return true. Otherwise return false.
|
48
|
+
*/
|
49
|
+
VALUE
|
50
|
+
rb_closed_q(VALUE self)
|
51
|
+
{
|
52
|
+
return CV_IS_SEQ_CLOSED(CVSEQ(self)) ? Qtrue : Qfalse;
|
53
|
+
}
|
54
|
+
|
55
|
+
/*
|
56
|
+
* If curve is convex, return true. Otherwise return false.
|
57
|
+
*/
|
58
|
+
VALUE
|
59
|
+
rb_convex_q(VALUE self)
|
60
|
+
{
|
61
|
+
return CV_IS_SEQ_CONVEX(CVSEQ(self)) ? Qtrue : Qfalse;
|
62
|
+
}
|
63
|
+
|
64
|
+
/*
|
65
|
+
* If curve is hole(inner contour), return true. Otherwise return false.
|
66
|
+
*/
|
67
|
+
VALUE
|
68
|
+
rb_hole_q(VALUE self)
|
69
|
+
{
|
70
|
+
return CV_IS_SEQ_HOLE(CVSEQ(self)) ? Qtrue : Qfalse;
|
71
|
+
}
|
72
|
+
|
73
|
+
/*
|
74
|
+
* no idia.
|
75
|
+
*/
|
76
|
+
VALUE
|
77
|
+
rb_simple_q(VALUE self)
|
78
|
+
{
|
79
|
+
return CV_IS_SEQ_SIMPLE(CVSEQ(self)) ? Qtrue : Qfalse;
|
80
|
+
}
|
81
|
+
|
82
|
+
/*
|
83
|
+
* call-seq:
|
84
|
+
* arc_length(<i>[slice = nil][,is_closed = nil]</i>) -> float
|
85
|
+
*
|
86
|
+
* Calculates contour perimeter or curve length.
|
87
|
+
* <i>slice</i> is starting and ending points of the curve.
|
88
|
+
* <i>is_closed</i> is indicates whether the curve is closed or not. There are 3 cases:
|
89
|
+
* * is_closed = true - the curve is assumed to be unclosed.
|
90
|
+
* * is_closed = false - the curve is assumed to be closed.
|
91
|
+
* * is_closed = nil (default) use self#close?
|
92
|
+
*/
|
93
|
+
VALUE
|
94
|
+
rb_arc_length(int argc, VALUE *argv, VALUE self)
|
95
|
+
{
|
96
|
+
VALUE slice, is_closed;
|
97
|
+
rb_scan_args(argc, argv, "02", &slice, &is_closed);
|
98
|
+
double length = 0;
|
99
|
+
try {
|
100
|
+
length = cvArcLength(CVARR(self),
|
101
|
+
NIL_P(slice) ? CV_WHOLE_SEQ : VALUE_TO_CVSLICE(slice),
|
102
|
+
TRUE_OR_FALSE(is_closed, -1));
|
103
|
+
}
|
104
|
+
catch (cv::Exception& e) {
|
105
|
+
raise_cverror(e);
|
106
|
+
}
|
107
|
+
return rb_float_new(length);
|
108
|
+
}
|
109
|
+
|
110
|
+
__NAMESPACE_END_CURVE
|
111
|
+
__NAMESPACE_END_OPENCV
|
112
|
+
|
data/ext/opencv/curve.h
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
curve.h -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#ifndef RUBY_OPENCV_CVSEQ_CURVE_H
|
11
|
+
#define RUBY_OPENCV_CVSEQ_CURVE_H
|
12
|
+
|
13
|
+
#include "opencv.h"
|
14
|
+
|
15
|
+
#define __NAMESPACE_BEGIN_CURVE namespace mCurve {
|
16
|
+
#define __NAMESPACE_END_CURVE }
|
17
|
+
|
18
|
+
__NAMESPACE_BEGIN_OPENCV
|
19
|
+
__NAMESPACE_BEGIN_CURVE
|
20
|
+
|
21
|
+
VALUE rb_module();
|
22
|
+
|
23
|
+
void define_ruby_module();
|
24
|
+
|
25
|
+
VALUE rb_closed_q(VALUE self);
|
26
|
+
VALUE rb_convex_q(VALUE self);
|
27
|
+
VALUE rb_hole_q(VALUE self);
|
28
|
+
VALUE rb_simple_q(VALUE self);
|
29
|
+
VALUE rb_arc_length(int argc, VALUE *argv, VALUE self);
|
30
|
+
|
31
|
+
__NAMESPACE_END_CURVE
|
32
|
+
__NAMESPACE_END_OPENCV
|
33
|
+
|
34
|
+
#endif // RUBY_OPENCV_CVSEQ_CURVE_H
|
@@ -0,0 +1,67 @@
|
|
1
|
+
/************************************************************
|
2
|
+
|
3
|
+
cvavgcomp.cpp -
|
4
|
+
|
5
|
+
$Author: lsxi $
|
6
|
+
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
8
|
+
|
9
|
+
************************************************************/
|
10
|
+
#include "cvavgcomp.h"
|
11
|
+
/*
|
12
|
+
* Document-class: OpenCV::CvAvgComp
|
13
|
+
*
|
14
|
+
* CvRect with parameter "neighbors".
|
15
|
+
* CvHaarClassifierCascade#detect_object.
|
16
|
+
*
|
17
|
+
* typedef struct CvAvgComp {
|
18
|
+
* CvRect rect;
|
19
|
+
* int neighbors;
|
20
|
+
* }
|
21
|
+
*/
|
22
|
+
__NAMESPACE_BEGIN_OPENCV
|
23
|
+
__NAMESPACE_BEGIN_AVGCOMP
|
24
|
+
|
25
|
+
VALUE rb_klass;
|
26
|
+
|
27
|
+
VALUE
|
28
|
+
rb_class()
|
29
|
+
{
|
30
|
+
return rb_klass;
|
31
|
+
}
|
32
|
+
|
33
|
+
void
|
34
|
+
define_ruby_class()
|
35
|
+
{
|
36
|
+
if (rb_klass)
|
37
|
+
return;
|
38
|
+
/*
|
39
|
+
* opencv = rb_define_module("OpenCV");
|
40
|
+
* cvrect = rb_define_class_under(opencv, "CvRect", rb_cObject);
|
41
|
+
*
|
42
|
+
* note: this comment is used by rdoc.
|
43
|
+
*/
|
44
|
+
VALUE opencv = rb_module_opencv(), cvrect = cCvRect::rb_class();
|
45
|
+
rb_klass = rb_define_class_under(opencv, "CvAvgComp", cvrect);
|
46
|
+
rb_define_alloc_func(rb_klass, rb_allocate);
|
47
|
+
rb_define_method(rb_klass, "neighbors", RUBY_METHOD_FUNC(rb_neighbors), 0);
|
48
|
+
}
|
49
|
+
|
50
|
+
VALUE
|
51
|
+
rb_allocate(VALUE klass)
|
52
|
+
{
|
53
|
+
CvAvgComp *ptr;
|
54
|
+
return Data_Make_Struct(klass, CvAvgComp, 0, -1, ptr);
|
55
|
+
}
|
56
|
+
|
57
|
+
/*
|
58
|
+
* Return neighbors.
|
59
|
+
*/
|
60
|
+
VALUE
|
61
|
+
rb_neighbors(VALUE self)
|
62
|
+
{
|
63
|
+
return INT2NUM(CVAVGCOMP(self)->neighbors);
|
64
|
+
}
|
65
|
+
|
66
|
+
__NAMESPACE_END_AVGCOMP
|
67
|
+
__NAMESPACE_END_OPENCV
|