opencv-ffi 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. data/.gitignore +7 -0
  2. data/Gemfile +15 -0
  3. data/README.md +126 -0
  4. data/Rakefile +52 -0
  5. data/docs/DocsIndex.md +1 -0
  6. data/docs/examples/load_image.rb +25 -0
  7. data/ext/Rakefile +13 -0
  8. data/ext/aishack-sift/.gitignore +4 -0
  9. data/ext/aishack-sift/Descriptor.h +34 -0
  10. data/ext/aishack-sift/KeyPoint.h +38 -0
  11. data/ext/aishack-sift/README +20 -0
  12. data/ext/aishack-sift/SIFT.cpp +1036 -0
  13. data/ext/aishack-sift/SIFT.h +84 -0
  14. data/ext/aishack-sift/example/.gitignore +2 -0
  15. data/ext/aishack-sift/example/Makefile +24 -0
  16. data/ext/aishack-sift/example/MySIFT.cpp +29 -0
  17. data/ext/aishack-sift/mkrf_conf.rb +13 -0
  18. data/ext/aishack-sift/siftlib.cpp +85 -0
  19. data/ext/eigen/.gitignore +4 -0
  20. data/ext/eigen/eigen_polynomial.cpp +41 -0
  21. data/ext/eigen/eigen_svd.cpp +100 -0
  22. data/ext/eigen/mkrf_conf.rb +14 -0
  23. data/ext/mkrf-monkey.rb +85 -0
  24. data/ext/mkrf-rakehelper-monkey.rb +52 -0
  25. data/ext/mkrf_conf.rb +3 -0
  26. data/ext/opencv-ffi/.gitignore +4 -0
  27. data/ext/opencv-ffi/matcher_helper.cpp +56 -0
  28. data/ext/opencv-ffi/mkrf_conf.rb +12 -0
  29. data/ext/opencv-ffi/vector_math.cpp +39 -0
  30. data/ext/opensurf/.gitignore +4 -0
  31. data/ext/opensurf/README +38 -0
  32. data/ext/opensurf/fasthessian.cpp +376 -0
  33. data/ext/opensurf/fasthessian.h +108 -0
  34. data/ext/opensurf/integral.cpp +58 -0
  35. data/ext/opensurf/integral.h +55 -0
  36. data/ext/opensurf/ipoint.cpp +108 -0
  37. data/ext/opensurf/ipoint.h +76 -0
  38. data/ext/opensurf/kmeans.h +172 -0
  39. data/ext/opensurf/mkrf_conf.rb +10 -0
  40. data/ext/opensurf/responselayer.h +92 -0
  41. data/ext/opensurf/surf.cpp +317 -0
  42. data/ext/opensurf/surf.h +66 -0
  43. data/ext/opensurf/surflib.cpp +98 -0
  44. data/ext/opensurf/surflib.h +96 -0
  45. data/ext/opensurf/utils.cpp +357 -0
  46. data/ext/opensurf/utils.h +63 -0
  47. data/lib/.gitignore +1 -0
  48. data/lib/opencv-ffi-ext/eigen.rb +84 -0
  49. data/lib/opencv-ffi-ext/features2d.rb +4 -0
  50. data/lib/opencv-ffi-ext/matcher_helper.rb +24 -0
  51. data/lib/opencv-ffi-ext/opensurf.rb +217 -0
  52. data/lib/opencv-ffi-ext/sift.rb +118 -0
  53. data/lib/opencv-ffi-ext/vector_math.rb +115 -0
  54. data/lib/opencv-ffi-wrappers.rb +7 -0
  55. data/lib/opencv-ffi-wrappers/core.rb +24 -0
  56. data/lib/opencv-ffi-wrappers/core/iplimage.rb +50 -0
  57. data/lib/opencv-ffi-wrappers/core/mat.rb +268 -0
  58. data/lib/opencv-ffi-wrappers/core/misc_draw.rb +44 -0
  59. data/lib/opencv-ffi-wrappers/core/point.rb +286 -0
  60. data/lib/opencv-ffi-wrappers/core/rect.rb +40 -0
  61. data/lib/opencv-ffi-wrappers/core/scalar.rb +104 -0
  62. data/lib/opencv-ffi-wrappers/core/size.rb +88 -0
  63. data/lib/opencv-ffi-wrappers/enumerable.rb +10 -0
  64. data/lib/opencv-ffi-wrappers/features2d.rb +17 -0
  65. data/lib/opencv-ffi-wrappers/features2d/image_patch.rb +322 -0
  66. data/lib/opencv-ffi-wrappers/features2d/star.rb +111 -0
  67. data/lib/opencv-ffi-wrappers/features2d/surf.rb +115 -0
  68. data/lib/opencv-ffi-wrappers/highgui.rb +10 -0
  69. data/lib/opencv-ffi-wrappers/imgproc.rb +4 -0
  70. data/lib/opencv-ffi-wrappers/imgproc/features.rb +35 -0
  71. data/lib/opencv-ffi-wrappers/imgproc/geometric.rb +39 -0
  72. data/lib/opencv-ffi-wrappers/matcher.rb +297 -0
  73. data/lib/opencv-ffi-wrappers/matrix.rb +37 -0
  74. data/lib/opencv-ffi-wrappers/misc.rb +41 -0
  75. data/lib/opencv-ffi-wrappers/misc/params.rb +34 -0
  76. data/lib/opencv-ffi-wrappers/sequence.rb +37 -0
  77. data/lib/opencv-ffi-wrappers/vectors.rb +38 -0
  78. data/lib/opencv-ffi.rb +12 -0
  79. data/lib/opencv-ffi/calib3d.rb +26 -0
  80. data/lib/opencv-ffi/core.rb +15 -0
  81. data/lib/opencv-ffi/core/draw.rb +68 -0
  82. data/lib/opencv-ffi/core/dynamic.rb +13 -0
  83. data/lib/opencv-ffi/core/library.rb +5 -0
  84. data/lib/opencv-ffi/core/operations.rb +122 -0
  85. data/lib/opencv-ffi/core/point.rb +22 -0
  86. data/lib/opencv-ffi/core/types.rb +172 -0
  87. data/lib/opencv-ffi/cvffi.rb +8 -0
  88. data/lib/opencv-ffi/features2d.rb +7 -0
  89. data/lib/opencv-ffi/features2d/library.rb +6 -0
  90. data/lib/opencv-ffi/features2d/star.rb +30 -0
  91. data/lib/opencv-ffi/features2d/surf.rb +38 -0
  92. data/lib/opencv-ffi/highgui.rb +31 -0
  93. data/lib/opencv-ffi/imgproc.rb +9 -0
  94. data/lib/opencv-ffi/imgproc/features.rb +37 -0
  95. data/lib/opencv-ffi/imgproc/geometric.rb +42 -0
  96. data/lib/opencv-ffi/imgproc/library.rb +6 -0
  97. data/lib/opencv-ffi/imgproc/misc.rb +39 -0
  98. data/lib/opencv-ffi/version.rb +3 -0
  99. data/opencv-ffi.gemspec +26 -0
  100. data/test/core/test_draw.rb +46 -0
  101. data/test/core/test_operations.rb +135 -0
  102. data/test/core/test_size.rb +14 -0
  103. data/test/core/test_text.rb +52 -0
  104. data/test/ext/test_eigen.rb +105 -0
  105. data/test/ext/test_opensurf.rb +35 -0
  106. data/test/ext/test_sift.rb +26 -0
  107. data/test/ext/test_vector_math.rb +85 -0
  108. data/test/features2d/test_surf.rb +63 -0
  109. data/test/imgproc/test_goodfeatures.rb +18 -0
  110. data/test/setup.rb +65 -0
  111. data/test/test_calib3d.rb +38 -0
  112. data/test/test_core.rb +26 -0
  113. data/test/test_ext.rb +8 -0
  114. data/test/test_features2d.rb +9 -0
  115. data/test/test_files/images/IMG_7088.JPG +0 -0
  116. data/test/test_files/images/IMG_7088_small.JPG +0 -0
  117. data/test/test_files/images/IMG_7089.JPG +0 -0
  118. data/test/test_highgui.rb +26 -0
  119. data/test/test_imgproc.rb +35 -0
  120. data/test/test_wrappers.rb +8 -0
  121. data/test/wrappers/core/test_draw.rb +41 -0
  122. data/test/wrappers/core/test_mat.rb +40 -0
  123. data/test/wrappers/core/test_operations.rb +35 -0
  124. data/test/wrappers/core/test_types.rb +235 -0
  125. data/test/wrappers/features2d/test_image_patch.rb +108 -0
  126. data/test/wrappers/test_imgproc.rb +87 -0
  127. data/test/wrappers/test_matcher.rb +96 -0
  128. data/test/wrappers/test_star.rb +28 -0
  129. data/test/wrappers/test_surf.rb +36 -0
  130. metadata +234 -0
@@ -0,0 +1,85 @@
1
+
2
+ require 'test/setup'
3
+ require 'opencv-ffi-ext/vector_math'
4
+ require 'opencv-ffi-wrappers/enumerable'
5
+ require 'benchmark'
6
+
7
+ class TestVectorMath < Test::Unit::TestCase
8
+
9
+ def setup
10
+ @zero_vector = CVFFI::Float64.new( "\0" )
11
+ @random_vector_one = CVFFI::Float64.new( "\0" )
12
+ @random_vector_two = CVFFI::Float64.new( "\0" )
13
+
14
+ CVFFI::Float64::nElem.times { |i|
15
+ @zero_vector.d[i] = 0.0
16
+ @random_vector_one.d[i] = rand
17
+ @random_vector_two.d[i] = rand
18
+ }
19
+ end
20
+
21
+
22
+ def test_L2distance
23
+
24
+ Benchmark.bm(10) do |x|
25
+ x.report("Zero vector") {
26
+ assert_equal 0.0, CVFFI::VectorMath::L2distance( @zero_vector, @zero_vector )
27
+ }
28
+
29
+ l2dist = 0.0
30
+ x.report("64-entry by hand") {
31
+ l2dist = @random_vector_one.inject_with_index(0.0) { |x, f, i|
32
+ x + (f - @random_vector_two.d[i])**2
33
+ }
34
+ }
35
+
36
+ x.report("Random vectors") {
37
+ assert_in_delta l2dist, CVFFI::VectorMath::L2distance( @random_vector_one, @random_vector_two ), 1e-3
38
+ }
39
+
40
+ end
41
+
42
+ end
43
+
44
+ def test_L2distance_8u
45
+ Benchmark.bm(10) do |x|
46
+ a = Array.new( 1000 ) { |i| rand(256) }
47
+ b = Array.new( 1000 ) { |i| rand(256) }
48
+
49
+ l2dist = 0.0
50
+ x.report("1000-entry uint8 in pure ruby") {
51
+ l2dist = a.inject_with_index(0.0) { |x,f,i|
52
+ x + (f-b[i])**2
53
+ }
54
+ }
55
+
56
+ x.report("With libcv-ffi") {
57
+ assert_in_delta l2dist, CVFFI::VectorMath::L2distance_8u( a, b )
58
+ }
59
+
60
+ end
61
+ end
62
+
63
+ class NativeUint8
64
+ include CVFFI::VectorMath::NativeVectors
65
+
66
+ define_vector :uint8, 10, :Uint8Vector
67
+
68
+ def self.new_vector
69
+ Uint8Vector.new '\0'
70
+ end
71
+ end
72
+
73
+ def test_native_vectors
74
+ a = NativeUint8.new_vector
75
+ p a
76
+ puts a.length
77
+
78
+ b = CVFFI::VectorMath::NativeVectors::ScalarVector.new( :uint8, 5 )
79
+ p b
80
+ b[0] = 1
81
+ p b[0]
82
+ p b.to_c
83
+ end
84
+
85
+ end
@@ -0,0 +1,63 @@
1
+
2
+
3
+ require 'test/setup'
4
+
5
+ require 'opencv-ffi'
6
+
7
+ class TestSURF < Test::Unit::TestCase
8
+
9
+ def setup
10
+ @img = CVFFI::cvLoadImage( TEST_IMAGE_FILE, CVFFI::CV_LOAD_IMAGE_COLOR )
11
+ end
12
+
13
+
14
+ def test_cvExtractSURF
15
+ kp_ptr = FFI::MemoryPointer.new :pointer
16
+ desc_ptr = FFI::MemoryPointer.new :pointer
17
+
18
+ mem_storage = CVFFI::cvCreateMemStorage( 0 )
19
+
20
+ greyImg = CVFFI::cvCreateImage( CVFFI::CvSize.new( { :height => @img.height,
21
+ :width => @img.width }),
22
+ :IPL_DEPTH_8U, 1 )
23
+ CVFFI::cvCvtColor( @img, greyImg, :CV_RGB2GRAY )
24
+
25
+ smallGreyImg = CVFFI::cvCreateImage( CVFFI::CvSize.new( { :height => greyImg.height/2,
26
+ :width => greyImg.width/2 } ),
27
+ :IPL_DEPTH_8U, 1 )
28
+
29
+ CVFFI::cvResize( greyImg, smallGreyImg, :CV_INTER_LINEAR )
30
+
31
+ #CVFFI::cvSaveImage( TestSetup::output_filename("greyImage.jpg"), smallGreyImg.to_ptr )
32
+
33
+ params = CVFFI::CvSURFParams.new( :hessianThreshold => 500.0,
34
+ :upright => 0,
35
+ :extended => 0,
36
+ :nOctaves => 3,
37
+ :nOctaveLayers => 4 )
38
+ CVFFI::cvExtractSURF( smallGreyImg, nil, kp_ptr, desc_ptr, mem_storage, params, :false )
39
+
40
+ assert_not_nil kp_ptr
41
+ assert_not_nil kp_ptr.read_pointer()
42
+
43
+ assert_not_nil desc_ptr
44
+ assert_not_nil desc_ptr.read_pointer()
45
+
46
+ keypoints = CVFFI::CvSeq.new( kp_ptr.read_pointer() )
47
+ descriptors = CVFFI::CvSeq.new( desc_ptr.read_pointer() )
48
+
49
+ #puts "#{keypoints.total} keypoints"
50
+ #puts "#{descriptors.total} descriptors"
51
+
52
+ (0...keypoints.total).each { |i|
53
+ kp = CVFFI::CvSURFPoint.new( CVFFI::cvGetSeqElem( keypoints.to_ptr, i ) )
54
+
55
+ # cvCircle takes a CvPoint(int), but the CvSURFPoint contains CvPoint2D32f, need
56
+ # to manually typecast...
57
+ CVFFI::cvCircle( smallGreyImg, CVFFI::CvPoint.new( :x => kp.pt.x.to_i, :y => kp.pt.y.to_i ), 5,
58
+ CVFFI::CvScalar.new( :w=>255, :x=>255, :y=>255, :z=>0 ), -1, 8, 0 )
59
+ }
60
+ CVFFI::cvSaveImage( TestSetup::output_filename("greyImagePts.jpg"), smallGreyImg )
61
+ end
62
+
63
+ end
@@ -0,0 +1,18 @@
1
+ require 'test/setup'
2
+ require 'opencv-ffi'
3
+ require 'find'
4
+
5
+ class TestGoodFeaturesToTrack < Test::Unit::TestCase
6
+
7
+ def test_goodFeaturesToTrack
8
+ # First, the "verbatim" approach, with some rubbish data
9
+ img = TestSetup::grey_test_image
10
+ eigImage = CVFFI::cvCreateMat( img.width, img.height, :CV_32F )
11
+ tmpImage = CVFFI::cvCreateMat( img.width, img.height, :CV_32F )
12
+
13
+ max_corners = 100
14
+ corners = CVFFI::cvGoodFeaturesToTrack( img, eigImage, tmpImage, max_corners, 0.5, 5 )
15
+
16
+ assert corners.length <= max_corners
17
+ end
18
+ end
@@ -0,0 +1,65 @@
1
+ # This must be the first require called, otherwise the
2
+ # results will be inaccurate
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+
6
+ require 'test/unit'
7
+ require 'pp'
8
+
9
+ require 'opencv-ffi/highgui'
10
+ require 'opencv-ffi/imgproc'
11
+
12
+
13
+ TEST_IMAGE_FILE = "test/test_files/images/IMG_7089.JPG"
14
+ SMALL_TEST_IMAGE_FILE = "test/test_files/images/IMG_7089_small.JPG"
15
+ TEST_IMAGE_FILE_TWO = "test/test_files/images/IMG_7088.JPG"
16
+
17
+ def recursive_test name
18
+ dirname = [ 'test', name] .join('/')
19
+ if File.directory? dirname
20
+ Find.find( dirname ) { |f|
21
+ require f if File.basename(f).match( "^test_[\w]*" )
22
+ }
23
+ end
24
+ end
25
+
26
+ module TestSetup
27
+
28
+ @dirname = "/tmp/opencv-ffi-test"
29
+
30
+ def self.test_image
31
+ CVFFI::cvLoadImage( TEST_IMAGE_FILE, CVFFI::CV_LOAD_IMAGE_COLOR )
32
+ end
33
+
34
+ def self.small_test_image
35
+ CVFFI::cvLoadImage( TEST_IMAGE_FILE, CVFFI::CV_LOAD_IMAGE_COLOR )
36
+ end
37
+
38
+
39
+ def self.grey_test_image
40
+ img = test_image
41
+ greyImg = CVFFI::cvCreateImage( CVFFI::CvSize.new( { :height => img.height,
42
+ :width => img.width }),
43
+ :IPL_DEPTH_8U, 1 )
44
+ CVFFI::cvCvtColor( img, greyImg, :CV_BGR2GRAY )
45
+ greyImg
46
+ end
47
+
48
+ def self.second_test_image
49
+ CVFFI::cvLoadImage( TEST_IMAGE_FILE_TWO, CVFFI::CV_LOAD_IMAGE_COLOR )
50
+ end
51
+
52
+ def self.save_image( fname, img )
53
+ fname += ".jpg" unless fname.match('\.')
54
+ CVFFI::cvSaveImage( output_filename(fname), img )
55
+ end
56
+
57
+ def self.output_filename( s )
58
+ FileUtils.mkdir_p @dirname unless FileTest::directory? @dirname
59
+ @dirname + '/' + s
60
+ end
61
+
62
+ EPSILON = 1e-3
63
+
64
+ end
65
+
@@ -0,0 +1,38 @@
1
+
2
+ require 'test/setup'
3
+ require 'opencv-ffi/calib3d'
4
+ require 'opencv-ffi-wrappers/misc'
5
+ require 'find'
6
+
7
+ recursive_test 'calib3d'
8
+
9
+ class TestCalib3d < Test::Unit::TestCase
10
+
11
+ def test_cvFundamentalMatrix
12
+ # First, the "verbatim" approach, with some rubbish data
13
+
14
+ points = 20
15
+ pointsOne = CVFFI::cvCreateMat( points, 2, :CV_32F )
16
+ pointsTwo = CVFFI::cvCreateMat( points, 2, :CV_32F )
17
+
18
+ points.times { |i|
19
+ u = CVFFI::CvScalar.new( :w => rand, :x => 0.0, :y => 0.0, :z => 0.0 )
20
+ v = CVFFI::CvScalar.new( :w => rand, :x => 0.0, :y => 0.0, :z => 0.0 )
21
+ w = CVFFI::CvScalar.new( :w => rand, :x => 0.0, :y => 0.0, :z => 0.0 )
22
+ x = CVFFI::CvScalar.new( :w => rand, :x => 0.0, :y => 0.0, :z => 0.0 )
23
+ CVFFI::cvSet2D( pointsOne, i, 0, u )
24
+ CVFFI::cvSet2D( pointsOne, i, 1, v )
25
+ CVFFI::cvSet2D( pointsTwo, i, 0, w )
26
+ CVFFI::cvSet2D( pointsTwo, i, 1, x )
27
+ }
28
+
29
+ fundamental = CVFFI::cvCreateMat( 3,3, :CV_32F )
30
+ status = CVFFI::cvCreateMat( points, 1, :CV_8U )
31
+
32
+ result = CVFFI::cvFindFundamentalMat( pointsOne, pointsTwo, fundamental, :CV_FM_RANSAC, 1.0, 0.99, status )
33
+
34
+ CVFFI::print_matrix fundamental, {:caption=>"Fundamental = "}
35
+ #CVFFI::print_matrix status, {:caption=>"Status = "}
36
+
37
+ end
38
+ end
@@ -0,0 +1,26 @@
1
+ require 'test/setup'
2
+ require 'opencv-ffi/core'
3
+ require 'find'
4
+
5
+ recursive_test 'core'
6
+
7
+ class TestCore < Test::Unit::TestCase
8
+
9
+ def test_cvPoint
10
+ p = CVFFI::CvPoint.new( {:x => 1, :y => 2} )
11
+
12
+ assert_not_nil p
13
+ assert_equal 1, p.x
14
+ assert_equal 2, p.y
15
+ end
16
+
17
+ def test_createImg
18
+ img = CVFFI::cvCreateImage( CVFFI::CvSize.new( :width=>100, :height=>100 ), 8, 1 )
19
+
20
+ assert_not_nil img
21
+ assert_equal 1, img.nChannels
22
+ assert_equal 8, img.depth
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,8 @@
1
+ require 'test/setup'
2
+ require 'find'
3
+
4
+ recursive_test 'ext'
5
+
6
+ class TestExt < Test::Unit::TestCase
7
+
8
+ end
@@ -0,0 +1,9 @@
1
+ require 'test/setup'
2
+ require 'opencv-ffi/features2d'
3
+ require 'find'
4
+
5
+ recursive_test 'features2d'
6
+
7
+ class TestFeatures2d < Test::Unit::TestCase
8
+
9
+ end
@@ -0,0 +1,26 @@
1
+
2
+ require 'test/setup'
3
+ require 'opencv-ffi/highgui'
4
+
5
+ class TestFFI < Test::Unit::TestCase
6
+
7
+ def test_cvLoadImageM_cvSaveImage
8
+ cvmat = CVFFI::cvLoadImageM( TEST_IMAGE_FILE, CVFFI::CV_LOAD_IMAGE_COLOR )
9
+
10
+ assert_not_nil cvmat
11
+ assert_equal cvmat.width, 3888
12
+ assert_equal cvmat.height, 2592
13
+
14
+ CVFFI::cvSaveImage( TestSetup::output_filename("asCvMat.jpg"), iplimage.to_ptr )
15
+ end
16
+
17
+ def test_cvLoadImageM_cvSaveImage
18
+ iplimage = CVFFI::cvLoadImage( TEST_IMAGE_FILE, CVFFI::CV_LOAD_IMAGE_COLOR )
19
+
20
+ assert_not_nil iplimage
21
+ assert_equal iplimage.width, 3888
22
+ assert_equal iplimage.height, 2592
23
+
24
+ CVFFI::cvSaveImage( TestSetup::output_filename("asIplImage.jpg"), iplimage.to_ptr )
25
+ end
26
+ end
@@ -0,0 +1,35 @@
1
+ require 'test/setup'
2
+ require 'opencv-ffi/imgproc'
3
+ require 'opencv-ffi/core'
4
+ require 'find'
5
+
6
+ recursive_test 'imgproc'
7
+
8
+ class TestImgproc < Test::Unit::TestCase
9
+
10
+ def test_cv2DRotationMatrix
11
+
12
+ center = CVFFI::CvPoint2D32f.new( :x => 0.0, :y => 0.0 )
13
+ mat = CVFFI::cvCreateMat( 2,3, :CV_32F )
14
+
15
+ CVFFI::cv2DRotationMatrix( center, 0.0, 1.0, mat )
16
+
17
+ # With 0 rotation, some elements should be 0.0
18
+
19
+ assert_in_delta 0.0, CVFFI::cvGetReal2D( mat, 0, 1 ), TestSetup::EPSILON
20
+ assert_in_delta 0.0, CVFFI::cvGetReal2D( mat, 1, 0 ), TestSetup::EPSILON
21
+ assert_in_delta CVFFI::cvGetReal2D( mat, 0, 0), CVFFI::cvGetReal2D( mat, 1, 1 ), TestSetup::EPSILON
22
+
23
+ a = []
24
+ 0.upto(1) { |i|
25
+ b = []
26
+ 0.upto(2) { |j|
27
+ b << CVFFI::cvGetReal2D( mat, i,j )
28
+ }
29
+ a << b
30
+ }
31
+
32
+ p a
33
+ end
34
+
35
+ end
@@ -0,0 +1,8 @@
1
+ require 'test/setup'
2
+ require 'find'
3
+
4
+ recursive_test 'wrappers'
5
+
6
+ class TestWrappers < Test::Unit::TestCase
7
+
8
+ end
@@ -0,0 +1,41 @@
1
+
2
+
3
+ require 'test/setup'
4
+ require 'opencv-ffi-wrappers/core/misc_draw'
5
+
6
+ class TestDrawWrappers < Test::Unit::TestCase
7
+
8
+ def setup
9
+ @img = TestSetup.test_image
10
+ end
11
+
12
+ def test_draw_point
13
+ p = CVFFI::Point.new( 500.0, 500.0 )
14
+
15
+ opts = { :radius => 50 }
16
+ CVFFI::draw_point( @img, p, opts)
17
+
18
+ TestSetup::save_image( "test_DrawPointWrapper", @img )
19
+ end
20
+
21
+ def test_put_text
22
+ font = CVFFI::CvFont.new '\0'
23
+ CVFFI::cvInitFont( font, :CV_FONT_HERSHEY_PLAIN, 2.0, 2.0, 0.0, 5, 8 )
24
+ img = CVFFI::cvCreateImage( CVFFI::CvSize.new( :height=>480, :width=>640), :IPL_DEPTH_32F, 3 )
25
+
26
+ color = CVFFI::Scalar.new( 0, 255, 0, 0, )
27
+ point = CVFFI::Point.new( 100, 100 )
28
+
29
+ a = "TEST TEST!"
30
+ CVFFI::put_text( img, a, point, { :font => font, :color => color } )
31
+
32
+ color[:r] = 255
33
+ CVFFI::put_text( img, a, point*2, { :face => :CV_FONT_HERSHEY_SIMPLEX,
34
+ :scale => 2.0,
35
+ :color => color } )
36
+
37
+ TestSetup::save_image( "test_FontWrapper", img )
38
+ end
39
+
40
+
41
+ end
@@ -0,0 +1,40 @@
1
+
2
+ require 'test/setup'
3
+ require 'opencv-ffi/core'
4
+ require 'opencv-ffi-wrappers/core'
5
+
6
+ class TestCoreMat < Test::Unit::TestCase
7
+
8
+ def test_MatInitializerDefaultType
9
+ # Default type is 32F
10
+ a = CVFFI::Mat.new( 5,5 )
11
+
12
+ a[1,2] = 1.0
13
+ assert_equal 1.0, a[1,2]
14
+ end
15
+
16
+
17
+ def test_MatInitializerIntType
18
+ a = CVFFI::Mat.new( 5,5, :CV_8U )
19
+
20
+ a[1,2] = 1.0
21
+ assert_equal 1, a[1,2]
22
+ end
23
+
24
+ def test_MatInitializeFromRows
25
+ a = [ [1,2,3],[4,5,6],[7,8,9] ]
26
+ m = CVFFI::Mat.rows( a, :CV_8U )
27
+
28
+ m.each_with_indices { |d,i,j|
29
+ assert_equal a[i][j], d
30
+ }
31
+ end
32
+
33
+ def test_MatEye
34
+ a = CVFFI::Mat.eye( 5, :CV_8U )
35
+
36
+ a.each_with_indices { |d, i,j|
37
+ assert_equal ( i==j ? 1 : 0 ), d
38
+ }
39
+ end
40
+ end