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
data/ext/opencv/window.h
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/************************************************************
|
|
2
|
+
|
|
3
|
+
window.h -
|
|
4
|
+
|
|
5
|
+
$Author: lsxi $
|
|
6
|
+
|
|
7
|
+
Copyright (C) 2005-2006 Masakazu Yonekura
|
|
8
|
+
|
|
9
|
+
************************************************************/
|
|
10
|
+
#ifndef RUBY_OPENCV_GUI_H
|
|
11
|
+
#include "gui.h"
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
#ifndef RUBY_OPENCV_GUI_WINDOW_H
|
|
15
|
+
#define RUBY_OPENCV_GUI_WINDOW_H
|
|
16
|
+
|
|
17
|
+
#include "opencv.h"
|
|
18
|
+
#define __NAMESPACE_BEGIN_WINDOW namespace cWindow {
|
|
19
|
+
#define __NAMESPACE_END_WINDOW }
|
|
20
|
+
|
|
21
|
+
__NAMESPACE_BEGIN_OPENCV
|
|
22
|
+
__NAMESPACE_BEGIN_GUI
|
|
23
|
+
|
|
24
|
+
typedef struct Window {
|
|
25
|
+
VALUE name;
|
|
26
|
+
VALUE image;
|
|
27
|
+
VALUE trackbars;
|
|
28
|
+
VALUE blocks;
|
|
29
|
+
} Window;
|
|
30
|
+
|
|
31
|
+
__NAMESPACE_BEGIN_WINDOW
|
|
32
|
+
|
|
33
|
+
void define_ruby_class();
|
|
34
|
+
|
|
35
|
+
VALUE rb_allocate(VALUE klass);
|
|
36
|
+
|
|
37
|
+
void window_mark(void *ptr);
|
|
38
|
+
void window_free(void *ptr);
|
|
39
|
+
VALUE rb_alive_q(VALUE self);
|
|
40
|
+
VALUE rb_initialize(int argc, VALUE *argv, VALUE self);
|
|
41
|
+
VALUE rb_destroy(VALUE self);
|
|
42
|
+
VALUE rb_destroy_all(VALUE klass);
|
|
43
|
+
VALUE rb_resize(int argc, VALUE *argv, VALUE self);
|
|
44
|
+
VALUE rb_move(int argc, VALUE *argv, VALUE self);
|
|
45
|
+
VALUE rb_show_image(VALUE self, VALUE img);
|
|
46
|
+
VALUE rb_set_trackbar(int argc, VALUE *argv, VALUE self);
|
|
47
|
+
VALUE rb_set_mouse_callback(int argc, VALUE* argv, VALUE self);
|
|
48
|
+
|
|
49
|
+
inline Window*
|
|
50
|
+
WINDOW(VALUE object) {
|
|
51
|
+
Window *ptr;
|
|
52
|
+
Data_Get_Struct(object, Window, ptr);
|
|
53
|
+
return ptr;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
inline const char*
|
|
57
|
+
GET_WINDOW_NAME(VALUE object) {
|
|
58
|
+
return StringValueCStr(WINDOW(object)->name);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
__NAMESPACE_END_WINDOW
|
|
62
|
+
__NAMESPACE_END_GUI
|
|
63
|
+
__NAMESPACE_END_OPENCV
|
|
64
|
+
|
|
65
|
+
#endif // RUBY_OPENCV_GUI_WINDOW_H
|
|
66
|
+
|
data/extconf.rb
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
=begin
|
|
3
|
+
create Makefile script for Ruby/OpenCV
|
|
4
|
+
|
|
5
|
+
usage : ruby extconf.rb
|
|
6
|
+
make && make install
|
|
7
|
+
|
|
8
|
+
VC : ruby extconf.rb
|
|
9
|
+
nmake
|
|
10
|
+
nmake install
|
|
11
|
+
=end
|
|
12
|
+
require "mkmf"
|
|
13
|
+
|
|
14
|
+
dir_config("opencv", "/usr/local/include", "/usr/local/lib")
|
|
15
|
+
dir_config("libxml2", "/usr/include", "/usr/lib")
|
|
16
|
+
|
|
17
|
+
opencv_headers = ["opencv2/core/core_c.h", "opencv2/core/core.hpp", "opencv2/imgproc/imgproc_c.h",
|
|
18
|
+
"opencv2/imgproc/imgproc.hpp", "opencv2/video/tracking.hpp", "opencv2/features2d/features2d.hpp",
|
|
19
|
+
"opencv2/flann/flann.hpp", "opencv2/calib3d/calib3d.hpp", "opencv2/objdetect/objdetect.hpp",
|
|
20
|
+
"opencv2/legacy/compat.hpp", "opencv2/legacy/legacy.hpp", "opencv2/highgui/highgui_c.h",
|
|
21
|
+
"opencv2/highgui/highgui.hpp", "opencv2/photo/photo.hpp", "opencv2/nonfree/nonfree.hpp"]
|
|
22
|
+
|
|
23
|
+
opencv_libraries = ["opencv_calib3d", "opencv_contrib", "opencv_core", "opencv_features2d",
|
|
24
|
+
"opencv_flann", "opencv_gpu", "opencv_highgui", "opencv_imgproc",
|
|
25
|
+
"opencv_legacy", "opencv_ml", "opencv_objdetect", "opencv_video",
|
|
26
|
+
"opencv_photo", "opencv_nonfree"]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
puts ">> Check the required libraries..."
|
|
30
|
+
|
|
31
|
+
OPENCV_VERSION_SUFFIX = '240'
|
|
32
|
+
case CONFIG["arch"]
|
|
33
|
+
when /mswin32/
|
|
34
|
+
opencv_libraries.map! {|lib| lib + OPENCV_VERSION_SUFFIX }
|
|
35
|
+
have_library("msvcrt")
|
|
36
|
+
opencv_libraries.each {|lib|
|
|
37
|
+
raise "#{lib}.lib not found." unless have_library(lib)
|
|
38
|
+
}
|
|
39
|
+
$CFLAGS << ' /EHsc'
|
|
40
|
+
when /mingw32/
|
|
41
|
+
opencv_libraries.map! {|lib| lib + OPENCV_VERSION_SUFFIX }
|
|
42
|
+
have_library("msvcrt")
|
|
43
|
+
opencv_libraries.each {|lib|
|
|
44
|
+
raise "lib#{lib} not found." unless have_library(lib)
|
|
45
|
+
}
|
|
46
|
+
else
|
|
47
|
+
opencv_libraries.each {|lib|
|
|
48
|
+
raise "lib#{lib} not found." unless have_library(lib)
|
|
49
|
+
}
|
|
50
|
+
have_library("stdc++")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Check the required headers
|
|
54
|
+
puts ">> Check the required headers..."
|
|
55
|
+
opencv_headers.each {|header|
|
|
56
|
+
raise "#{header} not found." unless have_header(header)
|
|
57
|
+
}
|
|
58
|
+
have_header("stdarg.h")
|
|
59
|
+
|
|
60
|
+
# Quick fix for 1.8.7
|
|
61
|
+
$CFLAGS << " -I#{File.dirname(__FILE__)}/ext/opencv"
|
|
62
|
+
|
|
63
|
+
# Create Makefile
|
|
64
|
+
create_makefile("opencv", "./ext/opencv")
|
|
65
|
+
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/test/helper.rb
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# -*- mode: ruby; coding: utf-8-unix -*-
|
|
3
|
+
require 'test/unit'
|
|
4
|
+
require 'digest/md5'
|
|
5
|
+
require 'opencv'
|
|
6
|
+
include OpenCV
|
|
7
|
+
|
|
8
|
+
class OpenCVTestCase < Test::Unit::TestCase
|
|
9
|
+
SAMPLE_DIR = File.expand_path(File.dirname(__FILE__)) + '/samples/'
|
|
10
|
+
FILENAME_CAT = SAMPLE_DIR + 'cat.jpg'
|
|
11
|
+
FILENAME_LENA256x256 = SAMPLE_DIR + 'lena-256x256.jpg'
|
|
12
|
+
FILENAME_LENA32x32 = SAMPLE_DIR + 'lena-32x32.jpg'
|
|
13
|
+
FILENAME_LENA_EYES = File.expand_path(File.dirname(__FILE__)) + '/samples/lena-eyes.jpg'
|
|
14
|
+
FILENAME_FRUITS = SAMPLE_DIR + 'fruits.jpg'
|
|
15
|
+
FILENAME_CONTOURS = File.expand_path(File.dirname(__FILE__)) + '/samples/contours.jpg'
|
|
16
|
+
HAARCASCADE_FRONTALFACE_ALT = SAMPLE_DIR + 'haarcascade_frontalface_alt.xml.gz'
|
|
17
|
+
AVI_SAMPLE = SAMPLE_DIR + 'movie_sample.avi'
|
|
18
|
+
|
|
19
|
+
DUMMY_OBJ = Digest::MD5.new # dummy object for argument type check test
|
|
20
|
+
|
|
21
|
+
def snap(*images)
|
|
22
|
+
n = -1
|
|
23
|
+
images.map! { |val|
|
|
24
|
+
n += 1
|
|
25
|
+
if val.is_a? Hash
|
|
26
|
+
val
|
|
27
|
+
elsif val.is_a? Array
|
|
28
|
+
{:title => val[0], :image => val[1] }
|
|
29
|
+
else
|
|
30
|
+
{:title => "snap-#{n}", :image => val }
|
|
31
|
+
end
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
pos = CvPoint.new(0, 0)
|
|
35
|
+
images.each { |img|
|
|
36
|
+
w = GUI::Window.new(img[:title])
|
|
37
|
+
w.show(img[:image])
|
|
38
|
+
w.move(pos)
|
|
39
|
+
pos.x += img[:image].width
|
|
40
|
+
if pos.x > 800
|
|
41
|
+
pos.y += img[:image].height
|
|
42
|
+
pos.x = 0
|
|
43
|
+
end
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
GUI::wait_key
|
|
47
|
+
GUI::Window::destroy_all
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def hash_img(img)
|
|
51
|
+
# Compute a hash for an image, useful for image comparisons
|
|
52
|
+
Digest::MD5.hexdigest(img.data)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
unless Test::Unit::TestCase.instance_methods.map {|m| m.to_sym }.include? :assert_false
|
|
56
|
+
def assert_false(actual, message = nil)
|
|
57
|
+
assert_equal(false, actual, message)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
alias original_assert_in_delta assert_in_delta
|
|
62
|
+
|
|
63
|
+
def assert_cvscalar_equal(expected, actual, message = nil)
|
|
64
|
+
assert_equal(CvScalar, actual.class, message)
|
|
65
|
+
assert_array_equal(expected.to_ary, actual.to_ary, message)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def assert_array_equal(expected, actual, message = nil)
|
|
69
|
+
assert_equal(expected.size, actual.size, message)
|
|
70
|
+
expected.zip(actual) { |e, a|
|
|
71
|
+
assert_equal(e, a, message)
|
|
72
|
+
}
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def assert_in_delta(expected, actual, delta)
|
|
76
|
+
if expected.is_a? CvScalar or actual.is_a? CvScalar
|
|
77
|
+
expected = expected.to_ary if expected.is_a? CvScalar
|
|
78
|
+
actual = actual.to_ary if actual.is_a? CvScalar
|
|
79
|
+
assert_in_delta(expected, actual ,delta)
|
|
80
|
+
elsif expected.is_a? Array and actual.is_a? Array
|
|
81
|
+
assert_equal(expected.size, actual.size)
|
|
82
|
+
expected.zip(actual) { |e, a|
|
|
83
|
+
original_assert_in_delta(e, a, delta)
|
|
84
|
+
}
|
|
85
|
+
else
|
|
86
|
+
original_assert_in_delta(expected, actual, delta)
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def create_cvmat(height, width, depth = :cv8u, channel = 4, &block)
|
|
91
|
+
m = CvMat.new(height, width, depth, channel)
|
|
92
|
+
block = lambda { |j, i, c| CvScalar.new(*([c + 1] * channel)) } unless block_given?
|
|
93
|
+
count = 0
|
|
94
|
+
height.times { |j|
|
|
95
|
+
width.times { |i|
|
|
96
|
+
m[j, i] = block.call(j, i, count)
|
|
97
|
+
count += 1
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
m
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def create_iplimage(width, height, depth = :cv8u, channel = 4, &block)
|
|
104
|
+
m = IplImage.new(width, height, depth, channel)
|
|
105
|
+
block = lambda { |j, i, c| CvScalar.new(*([c + 1] * channel)) } unless block_given?
|
|
106
|
+
count = 0
|
|
107
|
+
height.times { |j|
|
|
108
|
+
width.times { |i|
|
|
109
|
+
m[j, i] = block.call(j, i, count)
|
|
110
|
+
count += 1
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
m
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def assert_each_cvscalar(actual, delta = 0, &block)
|
|
117
|
+
raise unless block_given?
|
|
118
|
+
count = 0
|
|
119
|
+
actual.height.times { |j|
|
|
120
|
+
actual.width.times { |i|
|
|
121
|
+
expected = block.call(j, i, count)
|
|
122
|
+
if delta == 0
|
|
123
|
+
expected = expected.to_ary if expected.is_a? CvScalar
|
|
124
|
+
assert_array_equal(expected, actual[j, i].to_ary)
|
|
125
|
+
else
|
|
126
|
+
assert_in_delta(expected, actual[j, i], delta)
|
|
127
|
+
end
|
|
128
|
+
count += 1
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def print_cvmat(mat)
|
|
134
|
+
s = []
|
|
135
|
+
mat.height.times { |j|
|
|
136
|
+
a = []
|
|
137
|
+
mat.width.times { |i|
|
|
138
|
+
tmp = mat[j, i].to_ary.map {|m| m.to_f.round(2) }.join(',')
|
|
139
|
+
a << "[#{tmp}]"
|
|
140
|
+
}
|
|
141
|
+
s << a.join(' ')
|
|
142
|
+
}
|
|
143
|
+
puts s.join("\n")
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
data/test/runner.rb
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# -*- mode: ruby; coding: utf-8-unix -*-
|
|
3
|
+
require 'test/unit'
|
|
4
|
+
|
|
5
|
+
src_testdir = File.dirname(File.expand_path(__FILE__))
|
|
6
|
+
if Test::Unit.methods.include? :setup_argv
|
|
7
|
+
srcdir = File.dirname(src_testdir)
|
|
8
|
+
Test::Unit.setup_argv {|files|
|
|
9
|
+
if files.empty?
|
|
10
|
+
[src_testdir]
|
|
11
|
+
else
|
|
12
|
+
files.map {|f|
|
|
13
|
+
if File.exist? "#{src_testdir}/#{f}"
|
|
14
|
+
"#{src_testdir}/#{f}"
|
|
15
|
+
elsif File.exist? "#{srcdir}/#{f}"
|
|
16
|
+
"#{srcdir}/#{f}"
|
|
17
|
+
elsif File.exist? f
|
|
18
|
+
f
|
|
19
|
+
else
|
|
20
|
+
raise ArgumentError, "not found: #{f}"
|
|
21
|
+
end
|
|
22
|
+
}
|
|
23
|
+
end
|
|
24
|
+
}
|
|
25
|
+
elsif Test::Unit.constants.map {|c| c.to_sym }.include? :AutoRunner
|
|
26
|
+
Test::Unit::AutoRunner.run(true, src_testdir)
|
|
27
|
+
else
|
|
28
|
+
raise 'Test runner not found'
|
|
29
|
+
end
|
|
30
|
+
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/test/test_curve.rb
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# -*- mode: ruby; coding: utf-8-unix -*-
|
|
3
|
+
require 'test/unit'
|
|
4
|
+
require 'opencv'
|
|
5
|
+
require File.expand_path(File.dirname(__FILE__)) + '/helper'
|
|
6
|
+
|
|
7
|
+
include OpenCV
|
|
8
|
+
|
|
9
|
+
# Tests for OpenCV::Curve
|
|
10
|
+
class TestCurve < OpenCVTestCase
|
|
11
|
+
def setup
|
|
12
|
+
@contour1 = CvContour.new
|
|
13
|
+
|
|
14
|
+
mat0 = create_cvmat(128, 128, :cv8u, 1) { |j, i|
|
|
15
|
+
(j - 64) ** 2 + (i - 64) ** 2 <= (32 ** 2) ? CvColor::White : CvColor::Black
|
|
16
|
+
}
|
|
17
|
+
@contour2 = mat0.find_contours
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def test_closed
|
|
21
|
+
assert_false(@contour1.closed?)
|
|
22
|
+
assert(@contour2.closed?)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def test_convex
|
|
26
|
+
assert_false(@contour1.convex?)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_hole
|
|
30
|
+
assert_false(@contour1.hole?)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_simple
|
|
34
|
+
assert(@contour1.simple?)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_arc_length
|
|
38
|
+
assert_in_delta(211.480, @contour2.arc_length, 0.001)
|
|
39
|
+
assert_in_delta(32.181, @contour2.arc_length(CvSlice.new(0, 9), true), 0.001)
|
|
40
|
+
assert_in_delta(32.181, @contour2.arc_length(0..10, true), 0.001)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|