mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
added some tests
This commit is contained in:
parent
cce894071f
commit
c9e0877f36
2 changed files with 108 additions and 1 deletions
|
@ -1,6 +1,60 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
# -*- mode: ruby; coding: utf-8-unix -*-
|
||||||
|
|
||||||
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
||||||
|
require 'test/unit'
|
||||||
|
require 'digest/md5'
|
||||||
require 'opencv'
|
require 'opencv'
|
||||||
|
|
||||||
|
include OpenCV
|
||||||
|
|
||||||
|
class TestOpenCV < Test::Unit::TestCase
|
||||||
|
# mat_types = [CV_8UC1, CV_8UC2, CV_8UC3, CV_8UC4,
|
||||||
|
# CV_8SC1, CV_8SC2, CV_8SC3, CV_8SC4,
|
||||||
|
# CV_16UC1, CV_16UC2, CV_16UC3, CV_16UC4,
|
||||||
|
# CV_16SC1, CV_16SC2, CV_16SC3, CV_16SC4,
|
||||||
|
# CV_32SC1, CV_32SC2, CV_32SC3, CV_32SC4,
|
||||||
|
# CV_32FC1, CV_32FC2, CV_32FC3, CV_32FC4,
|
||||||
|
# CV_64FC1, CV_64FC2, CV_64FC3, CV_64FC4]
|
||||||
|
|
||||||
|
# mat_types_single = [CV_8UC1, CV_8SC1,
|
||||||
|
# CV_16UC1, CV_16SC1,
|
||||||
|
# CV_32SC1, CV_32FC1,
|
||||||
|
# CV_64FC1]
|
||||||
|
|
||||||
|
def setup
|
||||||
|
@depths = [CV_8U, CV_8S,
|
||||||
|
CV_16U, CV_16S,
|
||||||
|
CV_32S, CV_32F,
|
||||||
|
CV_64F]
|
||||||
|
@depthsize = {
|
||||||
|
CV_8U => 1,
|
||||||
|
CV_8S => 1,
|
||||||
|
CV_16U => 2,
|
||||||
|
CV_16S => 2,
|
||||||
|
CV_32S => 4,
|
||||||
|
CV_32F => 4,
|
||||||
|
CV_64F => 8
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_sample(filename, iscolor = nil)
|
||||||
|
IplImage::load('samples/' + filename, iscolor)
|
||||||
|
end
|
||||||
|
|
||||||
|
def snap(*images)
|
||||||
|
win = []
|
||||||
|
images.size.times { |i| win << GUI::Window.new("snap-#{i}") }
|
||||||
|
win.each_with_index { |w, i| w.show images[i] }
|
||||||
|
|
||||||
|
GUI::wait_key
|
||||||
|
GUI::Window::destroy_all
|
||||||
|
end
|
||||||
|
|
||||||
|
def hash_img(img)
|
||||||
|
# Compute a hash for an image, useful for image comparisons
|
||||||
|
Digest::MD5.hexdigest(img.data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
53
test/test_preliminary.rb
Executable file
53
test/test_preliminary.rb
Executable file
|
@ -0,0 +1,53 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
# -*- mode: ruby; coding: utf-8-unix -*-
|
||||||
|
|
||||||
|
require 'test/unit'
|
||||||
|
require 'digest/md5'
|
||||||
|
require 'opencv'
|
||||||
|
require 'pp'
|
||||||
|
require_relative 'test_opencv'
|
||||||
|
|
||||||
|
include OpenCV
|
||||||
|
|
||||||
|
# Tests to run first; check the handful of basic operations that the later tests rely on
|
||||||
|
class TestPreliminary < TestOpenCV
|
||||||
|
def test_lena
|
||||||
|
# Check that the lena jpg image has loaded correctly
|
||||||
|
img = get_sample('lena.jpg', false)
|
||||||
|
# snap(img) # uncomment this line to view the image, when regilding
|
||||||
|
assert_equal('2980cef5ac9bc061a5ab3f04775f3cf0', hash_img(img))
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_load
|
||||||
|
assert_raise(ArgumentError) { IplImage::load }
|
||||||
|
assert_raise(TypeError) { IplImage::load(4) }
|
||||||
|
assert_raise(ArgumentError) { IplImage::load('foo.jpg', 1, 1) }
|
||||||
|
assert_raise(StandardError) { IplImage::load('foo.jpg', 'foobar') }
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_types
|
||||||
|
assert_equal(IplImage.new(7, 5, CV_8U, 1).class, IplImage)
|
||||||
|
assert_equal(CvMat.new(5, 7, CV_32F).class, CvMat)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_to_s
|
||||||
|
[1, 4, 64, 512, 640].each { |w|
|
||||||
|
[1, 4, 64, 480, 512].each { |h|
|
||||||
|
[1, 2, 3, 4].each { |c|
|
||||||
|
@depths.each { |d|
|
||||||
|
expected_size = w * h * c * @depthsize[d]
|
||||||
|
|
||||||
|
mat = CvMat.new(w, h, d, c)
|
||||||
|
assert_equal(expected_size, mat.data.size)
|
||||||
|
|
||||||
|
# img = IplImage.new(w, h, d, c)
|
||||||
|
# expected_size += 4 - (expected_size % 4) unless (expected_size % 4) == 0
|
||||||
|
# assert_equal(expected_size, img.data.to_s.size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue