mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
Added a basic unit test.
This commit is contained in:
parent
0dead60224
commit
061a5830e5
4 changed files with 2219 additions and 1 deletions
|
@ -12,6 +12,8 @@ class OpenCVTestCase < Test::Unit::TestCase
|
|||
FILENAME_LENA32x32 = SAMPLE_DIR + 'lena-32x32.jpg'
|
||||
FILENAME_GIRLS_PLAY_AND_PLANT_FLOWERS_IN_THE_PARK = SAMPLE_DIR + 'girls-play-and-plant-flowers-in-the-park-725x480.jpg'
|
||||
HAARCASCADE_FRONTALFACE_ALT = SAMPLE_DIR + 'haarcascade_frontalface_alt.xml'
|
||||
BVLC_GOOGLENET_CAFFEMODEL = SAMPLE_DIR + 'bvlc_googlenet.caffemodel'
|
||||
BVLC_GOOGLENET_PROTXT = SAMPLE_DIR + 'bvlc_googlenet.prototxt'
|
||||
AVI_SAMPLE = SAMPLE_DIR + 'movie_sample.avi'
|
||||
|
||||
DUMMY_OBJ = Digest::MD5.new # dummy object for argument type check test
|
||||
|
@ -102,4 +104,3 @@ class OpenCVTestCase < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
BIN
test/samples/bvlc_googlenet.caffemodel
Normal file
BIN
test/samples/bvlc_googlenet.caffemodel
Normal file
Binary file not shown.
2156
test/samples/bvlc_googlenet.prototxt
Normal file
2156
test/samples/bvlc_googlenet.prototxt
Normal file
File diff suppressed because it is too large
Load diff
61
test/test_dnn.rb
Normal file
61
test/test_dnn.rb
Normal file
|
@ -0,0 +1,61 @@
|
|||
#!/usr/bin/env ruby
|
||||
# -*- mode: ruby; coding: utf-8 -*-
|
||||
require 'opencv'
|
||||
require File.expand_path(File.dirname(__FILE__)) + '/helper'
|
||||
|
||||
include Cv
|
||||
|
||||
class TestDnn < OpenCVTestCase
|
||||
def test_read_net
|
||||
c = Dnn.read_net(BVLC_GOOGLENET_PROTXT, BVLC_GOOGLENET_CAFFEMODEL)
|
||||
assert_equal(Dnn::Net, c.class)
|
||||
|
||||
assert_raise(TypeError) {
|
||||
Dnn.read_net(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_read_net_from_caffe
|
||||
c = Dnn.read_net_from_caffe(BVLC_GOOGLENET_PROTXT, BVLC_GOOGLENET_CAFFEMODEL)
|
||||
assert_equal(Dnn::Net, c.class)
|
||||
end
|
||||
|
||||
def test_blog_from_image
|
||||
i = Cv.imread(FILENAME_GIRLS_PLAY_AND_PLANT_FLOWERS_IN_THE_PARK)
|
||||
b = Dnn.blob_from_image(i, size: Cv::Size.new(224, 224))
|
||||
|
||||
assert_equal(Mat, b.class)
|
||||
assert_equal(224, b.size(2))
|
||||
assert_equal(224, b.size(3))
|
||||
end
|
||||
|
||||
def test_net_initialize
|
||||
c = Dnn::Net.new
|
||||
assert_equal(Dnn::Net, c.class)
|
||||
|
||||
c = Dnn::Net.new(BVLC_GOOGLENET_PROTXT, BVLC_GOOGLENET_CAFFEMODEL)
|
||||
assert_equal(Dnn::Net, c.class)
|
||||
|
||||
assert_raise(TypeError) {
|
||||
Dnn::Net.new(DUMMY_OBJ)
|
||||
}
|
||||
end
|
||||
|
||||
def test_net_empty
|
||||
c = Dnn::Net.new(BVLC_GOOGLENET_PROTXT, BVLC_GOOGLENET_CAFFEMODEL)
|
||||
assert_equal(false, c.empty?)
|
||||
|
||||
c = Dnn::Net.new
|
||||
assert_equal(true, c.empty?)
|
||||
end
|
||||
|
||||
def test_net_forward
|
||||
i = Cv.imread(FILENAME_GIRLS_PLAY_AND_PLANT_FLOWERS_IN_THE_PARK)
|
||||
|
||||
c = Dnn::Net.new(BVLC_GOOGLENET_PROTXT, BVLC_GOOGLENET_CAFFEMODEL)
|
||||
c.input = Dnn.blob_from_image(i, size: Cv::Size.new(224, 224))
|
||||
m = c.forward
|
||||
|
||||
assert_equal(Mat, m.class)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue