1
0
Fork 0
mirror of https://github.com/ruby-opencv/ruby-opencv synced 2023-03-27 23:22:12 -04:00

fixed a bug (sizes of velx, vely) of CvMat#optical_flow_bm

This commit is contained in:
ser1zw 2011-04-15 01:17:57 +09:00
parent b4f8c13ca4
commit ca92405ae8
2 changed files with 44 additions and 2 deletions

View file

@ -4968,11 +4968,13 @@ rb_optical_flow_bm(int argc, VALUE *argv, VALUE self)
block_size = BM_BLOCK_SIZE(options),
shift_size = BM_SHIFT_SIZE(options),
max_range = BM_MAX_RANGE(options),
velocity_size = cvSize(image_size.width / block_size.width, image_size.height / block_size.height);
velocity_size = cvSize((image_size.width - block_size.width) / shift_size.width,
(image_size.height - block_size.height) / shift_size.height);
if (NIL_P(velx) && NIL_P(vely)) {
velx = cCvMat::new_object(velocity_size, CV_MAKETYPE(CV_32F, 1));
vely = cCvMat::new_object(velocity_size, CV_MAKETYPE(CV_32F, 1));
} else {
}
else {
if (rb_obj_is_kind_of(velx, cCvMat::rb_class()) && rb_obj_is_kind_of(vely, cCvMat::rb_class()))
use_previous = 1;
else

View file

@ -1698,5 +1698,45 @@ class TestCvMat_imageprocessing < OpenCVTestCase
curr.optical_flow_lk('foobar', CvSize.new(3, 3))
}
end
def test_optical_flow_bm
size = 128
prev = create_cvmat(size, size, :cv8u, 1) { |j, i|
if ((i - (size / 2)) ** 2 ) + ((j - (size / 2)) ** 2 ) < size
CvColor::Black
else
CvColor::White
end
}
curr = create_cvmat(size, size, :cv8u, 1) { |j, i|
if ((i - (size / 2) - 10) ** 2) + ((j - (size / 2) - 7) ** 2 ) < size
CvColor::Black
else
CvColor::White
end
}
[curr.optical_flow_bm(prev, nil, nil, :block_size => CvSize.new(4, 4),
:shift_size => CvSize.new(1, 1), :max_range => CvSize.new(4, 4)),
curr.optical_flow_bm(prev)].each { |velx, vely|
assert_equal('08e73a6fa9af7684a5eddc4f30fd46e7', hash_img(velx))
assert_equal('aabaf1b7393b950c2297f567b6f57d5d', hash_img(vely))
}
velx, vely = curr.optical_flow_bm(prev, nil, nil, :block_size => CvSize.new(3, 3),
:shift_size => CvSize.new(2, 2), :max_range => CvSize.new(3, 3));
assert_equal('ec6441e73edf2b2933165034362fc129', hash_img(velx))
assert_equal('88b965b0003514f4239b9e97179f9c1e', hash_img(vely))
velx, vely = curr.optical_flow_bm(prev)
velx, vely = curr.optical_flow_bm(prev, velx, vely)
assert_equal('6ad6b7a5c935379c0df4b9ec5666f3de', hash_img(velx))
assert_equal('b317b0b9d4fdb0e5cd40beb0dd4143b4', hash_img(vely))
assert_raise(ArgumentError) {
curr.optical_flow_bm(prev, 'foo', 'bar')
}
end
end