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

Commit b4f8c13

Browse files
committed
tested CvMat#optical_flow_lk
1 parent 5c5434a commit b4f8c13

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

ext/cvmat.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ void define_ruby_class()
391391
rb_define_method(rb_klass, "snake_image", RUBY_METHOD_FUNC(rb_snake_image), -1);
392392

393393
rb_define_method(rb_klass, "optical_flow_hs", RUBY_METHOD_FUNC(rb_optical_flow_hs), -1);
394-
rb_define_method(rb_klass, "optical_flow_lk", RUBY_METHOD_FUNC(rb_optical_flow_lk), -1);
394+
rb_define_method(rb_klass, "optical_flow_lk", RUBY_METHOD_FUNC(rb_optical_flow_lk), 2);
395395
rb_define_method(rb_klass, "optical_flow_bm", RUBY_METHOD_FUNC(rb_optical_flow_bm), -1);
396396

397397
rb_define_singleton_method(rb_klass, "find_fundamental_mat_7point", RUBY_METHOD_FUNC(rb_find_fundamental_mat_7point), -1);
@@ -4919,11 +4919,10 @@ rb_optical_flow_hs(int argc, VALUE *argv, VALUE self)
49194919
* <i>win_size</i> is size of the averaging window used for grouping pixels.
49204920
*/
49214921
VALUE
4922-
rb_optical_flow_lk(int argc, VALUE *argv, VALUE self)
4922+
rb_optical_flow_lk(VALUE self, VALUE prev, VALUE win_size)
49234923
{
49244924
SUPPORT_8UC1_ONLY(self);
4925-
VALUE prev, win_size, velx, vely;
4926-
rb_scan_args(argc, argv, "20", &prev, &win_size);
4925+
VALUE velx, vely;
49274926
if (!rb_obj_is_kind_of(prev, cCvMat::rb_class()))
49284927
rb_raise(rb_eTypeError, "argument 1 (previous image) should be %s", rb_class2name(cCvMat::rb_class()));
49294928
velx = cCvMat::new_object(cvGetSize(CVARR(self)), CV_MAKETYPE(CV_32F, 1));

ext/cvmat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ VALUE rb_cam_shift(VALUE self, VALUE window, VALUE criteria);
253253
VALUE rb_snake_image(int argc, VALUE *argv, VALUE self);
254254
/* Optical Flow */
255255
VALUE rb_optical_flow_hs(int argc, VALUE *argv, VALUE self);
256-
VALUE rb_optical_flow_lk(int argc, VALUE *argv, VALUE self);
256+
VALUE rb_optical_flow_lk(VALUE self, VALUE prev, VALUE win_size);
257257
VALUE rb_optical_flow_bm(int argc, VALUE *argv, VALUE self);
258258
VALUE rb_optical_flow_pyr_lk(int argc, VALUE *argv, VALUE self);
259259

test/test_cvmat_imageprocessing.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,6 +1663,40 @@ def test_optical_flow_hs
16631663
velx, vely = curr.optical_flow_hs(prev, velx, vely)
16641664
assert_equal('08b50f3d4cb4cbbe443fada293e6af02', hash_img(velx))
16651665
assert_equal('4d302c8267388995ec85a4a26da5ffcc', hash_img(vely))
1666+
1667+
assert_raise(TypeError) {
1668+
curr.optical_flow_hs('foobar')
1669+
}
1670+
1671+
assert_raise(ArgumentError) {
1672+
curr.optical_flow_hs(prev, 'foo', 'bar')
1673+
}
1674+
end
1675+
1676+
def test_optical_flow_lk
1677+
size = 128
1678+
prev = create_cvmat(size, size, :cv8u, 1) { |j, i|
1679+
if ((i - (size / 2)) ** 2 ) + ((j - (size / 2)) ** 2 ) < size
1680+
CvColor::Black
1681+
else
1682+
CvColor::White
1683+
end
1684+
}
1685+
curr = create_cvmat(size, size, :cv8u, 1) { |j, i|
1686+
if ((i - (size / 2) - 10) ** 2) + ((j - (size / 2) - 7) ** 2 ) < size
1687+
CvColor::Black
1688+
else
1689+
CvColor::White
1690+
end
1691+
}
1692+
1693+
velx, vely = curr.optical_flow_lk(prev, CvSize.new(3, 3))
1694+
assert_equal('bea0c4c2b4b89ed1bb5e9ef5b68b8759', hash_img(velx))
1695+
assert_equal('aa643584d4eb175ab48896ff44646e06', hash_img(vely))
1696+
1697+
assert_raise(TypeError) {
1698+
curr.optical_flow_lk('foobar', CvSize.new(3, 3))
1699+
}
16661700
end
16671701
end
16681702

0 commit comments

Comments
 (0)