opencv 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. data/History.txt +5 -0
  2. data/License.txt +30 -0
  3. data/Manifest.txt +115 -0
  4. data/README.txt +47 -0
  5. data/Rakefile +34 -0
  6. data/examples/convexhull.rb +41 -0
  7. data/examples/face_detect.rb +25 -0
  8. data/examples/houghcircle.rb +23 -0
  9. data/examples/inpaint.png +0 -0
  10. data/examples/inpaint.rb +43 -0
  11. data/examples/paint.rb +72 -0
  12. data/examples/snake.rb +43 -0
  13. data/examples/stuff.jpg +0 -0
  14. data/ext/curve.cpp +103 -0
  15. data/ext/curve.h +34 -0
  16. data/ext/cvavgcomp.cpp +67 -0
  17. data/ext/cvavgcomp.h +39 -0
  18. data/ext/cvbox2d.cpp +114 -0
  19. data/ext/cvbox2d.h +53 -0
  20. data/ext/cvcapture.cpp +276 -0
  21. data/ext/cvcapture.h +54 -0
  22. data/ext/cvchain.cpp +184 -0
  23. data/ext/cvchain.h +43 -0
  24. data/ext/cvchaincode.cpp +49 -0
  25. data/ext/cvchaincode.h +43 -0
  26. data/ext/cvcircle32f.cpp +90 -0
  27. data/ext/cvcircle32f.h +53 -0
  28. data/ext/cvcondensation.cpp +230 -0
  29. data/ext/cvcondensation.h +49 -0
  30. data/ext/cvconnectedcomp.cpp +115 -0
  31. data/ext/cvconnectedcomp.h +46 -0
  32. data/ext/cvcontour.cpp +219 -0
  33. data/ext/cvcontour.h +47 -0
  34. data/ext/cvcontourtree.cpp +86 -0
  35. data/ext/cvcontourtree.h +41 -0
  36. data/ext/cvconvexitydefect.cpp +103 -0
  37. data/ext/cvconvexitydefect.h +42 -0
  38. data/ext/cverror.cpp +140 -0
  39. data/ext/cverror.h +79 -0
  40. data/ext/cvfont.cpp +173 -0
  41. data/ext/cvfont.h +56 -0
  42. data/ext/cvhaarclassifiercascade.cpp +159 -0
  43. data/ext/cvhaarclassifiercascade.h +41 -0
  44. data/ext/cvhistogram.cpp +200 -0
  45. data/ext/cvhistogram.h +51 -0
  46. data/ext/cvindex.cpp +73 -0
  47. data/ext/cvindex.h +40 -0
  48. data/ext/cvline.cpp +106 -0
  49. data/ext/cvline.h +52 -0
  50. data/ext/cvmat.cpp +4809 -0
  51. data/ext/cvmat.h +286 -0
  52. data/ext/cvmatnd.cpp +44 -0
  53. data/ext/cvmatnd.h +28 -0
  54. data/ext/cvmemstorage.cpp +64 -0
  55. data/ext/cvmemstorage.h +53 -0
  56. data/ext/cvmoments.cpp +204 -0
  57. data/ext/cvmoments.h +48 -0
  58. data/ext/cvpoint.cpp +229 -0
  59. data/ext/cvpoint.h +59 -0
  60. data/ext/cvpoint2d32f.cpp +213 -0
  61. data/ext/cvpoint2d32f.h +61 -0
  62. data/ext/cvpoint3d32f.cpp +245 -0
  63. data/ext/cvpoint3d32f.h +64 -0
  64. data/ext/cvrect.cpp +340 -0
  65. data/ext/cvrect.h +79 -0
  66. data/ext/cvscalar.cpp +227 -0
  67. data/ext/cvscalar.h +63 -0
  68. data/ext/cvseq.cpp +583 -0
  69. data/ext/cvseq.h +71 -0
  70. data/ext/cvset.cpp +63 -0
  71. data/ext/cvset.h +39 -0
  72. data/ext/cvsize.cpp +223 -0
  73. data/ext/cvsize.h +63 -0
  74. data/ext/cvsize2d32f.cpp +180 -0
  75. data/ext/cvsize2d32f.h +59 -0
  76. data/ext/cvslice.cpp +82 -0
  77. data/ext/cvslice.h +53 -0
  78. data/ext/cvsparsemat.cpp +44 -0
  79. data/ext/cvsparsemat.h +28 -0
  80. data/ext/cvtermcriteria.cpp +183 -0
  81. data/ext/cvtermcriteria.h +71 -0
  82. data/ext/cvtwopoints.cpp +98 -0
  83. data/ext/cvtwopoints.h +50 -0
  84. data/ext/cvvector.cpp +206 -0
  85. data/ext/cvvector.h +54 -0
  86. data/ext/cvvideowriter.cpp +116 -0
  87. data/ext/cvvideowriter.h +41 -0
  88. data/ext/extconf.rb +61 -0
  89. data/ext/gui.cpp +65 -0
  90. data/ext/gui.h +33 -0
  91. data/ext/iplconvkernel.cpp +177 -0
  92. data/ext/iplconvkernel.h +52 -0
  93. data/ext/iplimage.cpp +238 -0
  94. data/ext/iplimage.h +54 -0
  95. data/ext/mouseevent.cpp +184 -0
  96. data/ext/mouseevent.h +59 -0
  97. data/ext/opencv.cpp +481 -0
  98. data/ext/opencv.h +356 -0
  99. data/ext/point3dset.cpp +41 -0
  100. data/ext/point3dset.h +31 -0
  101. data/ext/pointset.cpp +238 -0
  102. data/ext/pointset.h +69 -0
  103. data/ext/trackbar.cpp +122 -0
  104. data/ext/trackbar.h +65 -0
  105. data/ext/window.cpp +368 -0
  106. data/ext/window.h +56 -0
  107. data/images/CvMat_sobel.png +0 -0
  108. data/images/CvMat_sub_rect.png +0 -0
  109. data/images/CvSeq_relationmap.png +0 -0
  110. data/images/face_detect_from_lena.jpg +0 -0
  111. data/lib/opencv.rb +3 -0
  112. data/lib/version.rb +3 -0
  113. data/setup/setup.cygwin.rb +120 -0
  114. data/setup/setup.mingw.rb +99 -0
  115. data/setup/setup.mswin32.rb +103 -0
  116. data/test/test_opencv.rb +4 -0
  117. metadata +191 -0
@@ -0,0 +1,5 @@
1
+ === 0.0.6 / 2008-06-27
2
+
3
+ * First gem release.
4
+
5
+ * Some OpenCV function wrapped.
@@ -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.
@@ -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
@@ -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
@@ -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
@@ -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
+
@@ -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
+