Skip to content
This repository has been archived by the owner on Dec 3, 2021. It is now read-only.

Commit

Permalink
fixed a bug (sizes of velx, vely) of CvMat#optical_flow_bm
Browse files Browse the repository at this point in the history
  • Loading branch information
ser1zw committed Apr 14, 2011
1 parent b4f8c13 commit ca92405
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ext/cvmat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions test/test_cvmat_imageprocessing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1698,5 +1698,45 @@ def test_optical_flow_lk
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

0 comments on commit ca92405

Please sign in to comment.