mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
fixed a bug of CvMat.find_fundamental_mat_ransac (size of status matrix), and tested it
This commit is contained in:
parent
e56749c70d
commit
ac62bd7988
5 changed files with 87 additions and 39 deletions
|
@ -5039,7 +5039,7 @@ rb_find_fundamental_mat_8point(VALUE klass, VALUE points1, VALUE points2)
|
||||||
* CvMat.find_fundamental_mat_ransac(<i>points1, points2[,options = {}]</i>) -> fundamental_matrix(cvmat) or nil
|
* CvMat.find_fundamental_mat_ransac(<i>points1, points2[,options = {}]</i>) -> fundamental_matrix(cvmat) or nil
|
||||||
*
|
*
|
||||||
* Calculates fundamental matrix from corresponding points, use for RANSAC algorism.
|
* Calculates fundamental matrix from corresponding points, use for RANSAC algorism.
|
||||||
* <i>points1</i> and <i>points2</i> should be 2x7 or 3x7 single-channel, or 1x7 multi-channel matrix.
|
* <i>points1</i> and <i>points2</i> should be 2xN, Nx2, 3xN or Nx3 1-channel, or 1xN or Nx1 multi-channel matrix (N >= 8).
|
||||||
* <i>option</i> should be Hash include these keys.
|
* <i>option</i> should be Hash include these keys.
|
||||||
* :with_status (true or false)
|
* :with_status (true or false)
|
||||||
* If set true, return fundamental_matrix and status. [fundamental_matrix, status]
|
* If set true, return fundamental_matrix and status. [fundamental_matrix, status]
|
||||||
|
@ -5059,13 +5059,17 @@ rb_find_fundamental_mat_ransac(int argc, VALUE *argv, VALUE klass)
|
||||||
int num = 0;
|
int num = 0;
|
||||||
rb_scan_args(argc, argv, "21", &points1, &points2, &option);
|
rb_scan_args(argc, argv, "21", &points1, &points2, &option);
|
||||||
option = FIND_FUNDAMENTAL_MAT_OPTION(option);
|
option = FIND_FUNDAMENTAL_MAT_OPTION(option);
|
||||||
fundamental_matrix = cCvMat::new_object(3, 3, CV_32FC1);
|
fundamental_matrix = cCvMat::new_object(3, 3, CVMAT(points1)->type);
|
||||||
if(FFM_WITH_STATUS(option)){
|
if(FFM_WITH_STATUS(option)){
|
||||||
status = cCvMat::new_object(cvGetSize(CVARR(points1)), CV_8UC1);
|
CvMat *points1_ptr = CVMAT(points1);
|
||||||
num = cvFindFundamentalMat(CVMAT(points1), CVMAT(points2), CVMAT(fundamental_matrix), CV_FM_RANSAC, FFM_MAXIMUM_DISTANCE(option), FFM_DESIRABLE_LEVEL(option), CVMAT(status));
|
int status_len = (points1_ptr->rows > points1_ptr->cols) ? points1_ptr->rows : points1_ptr->cols;
|
||||||
|
status = cCvMat::new_object(1, status_len, CV_8UC1);
|
||||||
|
num = cvFindFundamentalMat(CVMAT(points1), CVMAT(points2), CVMAT(fundamental_matrix), CV_FM_RANSAC,
|
||||||
|
FFM_MAXIMUM_DISTANCE(option), FFM_DESIRABLE_LEVEL(option), CVMAT(status));
|
||||||
return num == 0 ? Qnil : rb_ary_new3(2, fundamental_matrix, status);
|
return num == 0 ? Qnil : rb_ary_new3(2, fundamental_matrix, status);
|
||||||
}else{
|
}else{
|
||||||
num = cvFindFundamentalMat(CVMAT(points1), CVMAT(points2), CVMAT(fundamental_matrix), CV_FM_RANSAC, FFM_MAXIMUM_DISTANCE(option), FFM_DESIRABLE_LEVEL(option), NULL);
|
num = cvFindFundamentalMat(CVMAT(points1), CVMAT(points2), CVMAT(fundamental_matrix), CV_FM_RANSAC,
|
||||||
|
FFM_MAXIMUM_DISTANCE(option), FFM_DESIRABLE_LEVEL(option), NULL);
|
||||||
return num == 0 ? Qnil : fundamental_matrix;
|
return num == 0 ? Qnil : fundamental_matrix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 23 KiB |
Binary file not shown.
Before Width: | Height: | Size: 158 KiB |
|
@ -1936,6 +1936,84 @@ class TestCvMat < OpenCVTestCase
|
||||||
assert_in_delta(val, f_mat[i][0], 1.0e-5)
|
assert_in_delta(val, f_mat[i][0], 1.0e-5)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_find_fundamental_mat_ransac
|
||||||
|
points1 = [[488.362, 169.911],
|
||||||
|
[449.488, 174.44],
|
||||||
|
[408.565, 179.669],
|
||||||
|
[364.512, 184.56],
|
||||||
|
[491.483, 122.366],
|
||||||
|
[451.512, 126.56],
|
||||||
|
[409.502, 130.342],
|
||||||
|
[365.5, 134.0],
|
||||||
|
[494.335, 74.544],
|
||||||
|
[453.5, 76.5],
|
||||||
|
[411.646, 79.5901],
|
||||||
|
[366.498, 81.6577],
|
||||||
|
[453.5, 76.5],
|
||||||
|
[411.646, 79.5901],
|
||||||
|
[366.498, 81.6577]]
|
||||||
|
points2 = [[526.605, 213.332],
|
||||||
|
[470.485, 207.632],
|
||||||
|
[417.5, 201.0],
|
||||||
|
[367.485, 195.632],
|
||||||
|
[530.673, 156.417],
|
||||||
|
[473.749, 151.39],
|
||||||
|
[419.503, 146.656],
|
||||||
|
[368.669, 142.565],
|
||||||
|
[534.632, 97.5152],
|
||||||
|
[475.84, 94.6777],
|
||||||
|
[421.16, 90.3223],
|
||||||
|
[368.5, 87.5],
|
||||||
|
[475.84, 94.6777],
|
||||||
|
[421.16, 90.3223],
|
||||||
|
[368.5, 87.5]]
|
||||||
|
|
||||||
|
mat1 = CvMat.new(points1.size, 2, :cv64f, 1)
|
||||||
|
mat2 = CvMat.new(points2.size, 2, :cv64f, 1)
|
||||||
|
|
||||||
|
points1.each_with_index { |pt, i|
|
||||||
|
mat1[i, 0] = CvScalar.new(pt[0])
|
||||||
|
mat1[i, 1] = CvScalar.new(pt[1])
|
||||||
|
}
|
||||||
|
points2.each_with_index { |pt, i|
|
||||||
|
mat2[i, 0] = CvScalar.new(pt[0])
|
||||||
|
mat2[i, 1] = CvScalar.new(pt[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
# default
|
||||||
|
[CvMat.find_fundamental_mat_ransac(mat1, mat2, :with_status => false,
|
||||||
|
:maximum_distance => 1.0, :desirable_level => 0.99),
|
||||||
|
CvMat.find_fundamental_mat_ransac(mat1, mat2)].each { |f_mat|
|
||||||
|
assert_equal(3, f_mat.rows)
|
||||||
|
assert_equal(3, f_mat.cols)
|
||||||
|
expected = [0.000010, 0.000039, -0.011141,
|
||||||
|
-0.000045, -0.000001, 0.019631,
|
||||||
|
0.004873, -0.017604, 1.000000]
|
||||||
|
expected.each_with_index { |val, i|
|
||||||
|
assert_in_delta(val, f_mat[i][0], 1.0e-5)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# with options
|
||||||
|
f_mat, status = CvMat.find_fundamental_mat_ransac(mat1, mat2, :with_status => true,
|
||||||
|
:maximum_distance => 2.0, :desirable_level => 0.8)
|
||||||
|
assert_equal(3, f_mat.rows)
|
||||||
|
assert_equal(3, f_mat.cols)
|
||||||
|
assert_equal(1, status.rows)
|
||||||
|
assert_equal(points1.size, status.cols)
|
||||||
|
|
||||||
|
expected_f_mat = [0.000009, 0.000030, -0.010692,
|
||||||
|
-0.000039, 0.000000, 0.020567,
|
||||||
|
0.004779, -0.018064, 1.000000]
|
||||||
|
expected_f_mat.each_with_index { |val, i|
|
||||||
|
assert_in_delta(val, f_mat[i][0], 1.0e-5)
|
||||||
|
}
|
||||||
|
expected_status = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
|
||||||
|
expected_status.each_with_index { |val, i|
|
||||||
|
assert_in_delta(val, status[i][0], 1.0e-5)
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
#!/usr/bin/env ruby
|
|
||||||
# -*- mode: ruby; coding: utf-8-unix -*-
|
|
||||||
require 'test/unit'
|
|
||||||
require 'opencv'
|
|
||||||
require File.expand_path(File.dirname(__FILE__)) + '/helper'
|
|
||||||
|
|
||||||
include OpenCV
|
|
||||||
|
|
||||||
# Tests for OpenCV::IplImage
|
|
||||||
class TestIplImage < OpenCVTestCase
|
|
||||||
def should_classify_images_as(filename, classification)
|
|
||||||
assert_equal(OpenCV::IplImage::load(filename, OpenCV::CV_LOAD_IMAGE_GRAYSCALE).smoothness[0], classification)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_smoothness
|
|
||||||
asset_path = File.join(File.dirname(__FILE__), 'samples')
|
|
||||||
|
|
||||||
for image in Array.new(9) { |e| e = File.join(asset_path, "smooth%d.jpg") % e } do
|
|
||||||
should_classify_images_as image, :smooth
|
|
||||||
end
|
|
||||||
|
|
||||||
for image in Array.new(2) { |e| e = File.join(asset_path, "messy%d.jpg") % e } do
|
|
||||||
should_classify_images_as image, :messy
|
|
||||||
end
|
|
||||||
|
|
||||||
for image in Array.new(10) { |e| e = File.join(asset_path, "blank%d.jpg") % e } do
|
|
||||||
should_classify_images_as image, :blank
|
|
||||||
end
|
|
||||||
|
|
||||||
for image in Array.new(2) { |e| e = File.join(asset_path, "partially_blank%d.jpg") % e } do
|
|
||||||
should_classify_images_as image, :blank
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Add table
Reference in a new issue