mirror of
https://github.com/ruby-opencv/ruby-opencv
synced 2023-03-27 23:22:12 -04:00
change return values of CvMat#find_chessboard_corners
Add pattern_was_found, which indicates whether the complete board was found or not. This value will be used as an argument for CvMat#draw_chessboard_corners (to be implemented).
This commit is contained in:
parent
4ac425411d
commit
f8d9ce4a24
2 changed files with 17 additions and 10 deletions
|
@ -3701,9 +3701,10 @@ rb_corner_harris(int argc, VALUE *argv, VALUE self)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
* find_chessboard_corners(pattern_size, flag = CV_CALIB_CB_ADAPTIVE_THRESH) -> Array<CvPoint2D32f>
|
* find_chessboard_corners(pattern_size, flag = CV_CALIB_CB_ADAPTIVE_THRESH) -> Array<Array<CvPoint2D32f>, Boolean>
|
||||||
*
|
*
|
||||||
* Returns the positions of internal corners of the chessboard.
|
* Returns an array which includes the positions of internal corners of the chessboard, and
|
||||||
|
* a parameter indicating whether the complete board was found or not.
|
||||||
*
|
*
|
||||||
* pattern_size (CvSize) - Number of inner corners per a chessboard row and column.
|
* pattern_size (CvSize) - Number of inner corners per a chessboard row and column.
|
||||||
* flags (Integer) - Various operation flags that can be zero or a combination of the following values
|
* flags (Integer) - Various operation flags that can be zero or a combination of the following values
|
||||||
|
@ -3727,8 +3728,9 @@ rb_find_chessboard_corners(int argc, VALUE *argv, VALUE self)
|
||||||
CvSize pattern_size = VALUE_TO_CVSIZE(pattern_size_val);
|
CvSize pattern_size = VALUE_TO_CVSIZE(pattern_size_val);
|
||||||
CvPoint2D32f* corners = ALLOCA_N(CvPoint2D32f, pattern_size.width * pattern_size.height);
|
CvPoint2D32f* corners = ALLOCA_N(CvPoint2D32f, pattern_size.width * pattern_size.height);
|
||||||
int num_found_corners = 0;
|
int num_found_corners = 0;
|
||||||
|
int pattern_was_found = 0;
|
||||||
try {
|
try {
|
||||||
cvFindChessboardCorners(CVARR(self), pattern_size, corners, &num_found_corners, flag);
|
pattern_was_found = cvFindChessboardCorners(CVARR(self), pattern_size, corners, &num_found_corners, flag);
|
||||||
}
|
}
|
||||||
catch (cv::Exception& e) {
|
catch (cv::Exception& e) {
|
||||||
raise_cverror(e);
|
raise_cverror(e);
|
||||||
|
@ -3739,7 +3741,8 @@ rb_find_chessboard_corners(int argc, VALUE *argv, VALUE self)
|
||||||
rb_ary_store(found_corners, i, cCvPoint2D32f::new_object(corners[i]));
|
rb_ary_store(found_corners, i, cCvPoint2D32f::new_object(corners[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
return found_corners;
|
VALUE found = (pattern_was_found > 0) ? Qtrue : Qfalse;
|
||||||
|
return rb_assoc_new(found_corners, found);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -188,11 +188,11 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
||||||
def test_find_chessboard_corners
|
def test_find_chessboard_corners
|
||||||
mat = CvMat.load(FILENAME_CHESSBOARD, CV_LOAD_IMAGE_GRAYSCALE)
|
mat = CvMat.load(FILENAME_CHESSBOARD, CV_LOAD_IMAGE_GRAYSCALE)
|
||||||
pattern_size = CvSize.new(4, 4)
|
pattern_size = CvSize.new(4, 4)
|
||||||
corners1 = mat.find_chessboard_corners(pattern_size)
|
corners1, found1 = mat.find_chessboard_corners(pattern_size)
|
||||||
corners2 = mat.find_chessboard_corners(pattern_size, CV_CALIB_CB_ADAPTIVE_THRESH)
|
corners2, found2 = mat.find_chessboard_corners(pattern_size, CV_CALIB_CB_ADAPTIVE_THRESH)
|
||||||
corners3 = mat.find_chessboard_corners(pattern_size, CV_CALIB_CB_NORMALIZE_IMAGE)
|
corners3, found3 = mat.find_chessboard_corners(pattern_size, CV_CALIB_CB_NORMALIZE_IMAGE)
|
||||||
corners4 = mat.find_chessboard_corners(pattern_size, CV_CALIB_CB_FILTER_QUADS)
|
corners4, found4 = mat.find_chessboard_corners(pattern_size, CV_CALIB_CB_FILTER_QUADS)
|
||||||
corners5 = mat.find_chessboard_corners(pattern_size, CV_CALIB_CB_FAST_CHECK)
|
corners5, found5 = mat.find_chessboard_corners(pattern_size, CV_CALIB_CB_FAST_CHECK)
|
||||||
|
|
||||||
expected = [[39, 39], [79, 39], [119, 39], [159, 39], [39, 79], [79, 79],
|
expected = [[39, 39], [79, 39], [119, 39], [159, 39], [39, 79], [79, 79],
|
||||||
[119, 79], [159, 78], [38, 119], [79, 119], [119, 119], [158, 118],
|
[119, 79], [159, 78], [38, 119], [79, 119], [119, 119], [158, 118],
|
||||||
|
@ -204,6 +204,9 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
||||||
assert_in_delta(e[1], a.y, 3.0)
|
assert_in_delta(e[1], a.y, 3.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
[found1, found2, found3, found4, found5].each { |found|
|
||||||
|
assert(found)
|
||||||
|
}
|
||||||
|
|
||||||
assert_raise(TypeError) {
|
assert_raise(TypeError) {
|
||||||
mat.find_chessboard_corners(DUMMY_OBJ)
|
mat.find_chessboard_corners(DUMMY_OBJ)
|
||||||
|
@ -216,7 +219,7 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
||||||
def test_find_corner_sub_pix
|
def test_find_corner_sub_pix
|
||||||
mat = CvMat.load(FILENAME_CHESSBOARD, CV_LOAD_IMAGE_GRAYSCALE)
|
mat = CvMat.load(FILENAME_CHESSBOARD, CV_LOAD_IMAGE_GRAYSCALE)
|
||||||
pattern_size = CvSize.new(4, 4)
|
pattern_size = CvSize.new(4, 4)
|
||||||
corners = mat.find_chessboard_corners(pattern_size)
|
corners, found = mat.find_chessboard_corners(pattern_size)
|
||||||
expected = [[39, 39], [79, 39], [119, 39], [159, 39], [39, 79], [79, 79],
|
expected = [[39, 39], [79, 39], [119, 39], [159, 39], [39, 79], [79, 79],
|
||||||
[119, 79], [159, 78], [38, 119], [79, 119], [119, 119], [158, 118],
|
[119, 79], [159, 78], [38, 119], [79, 119], [119, 119], [158, 118],
|
||||||
[39, 159], [79, 159], [119, 159], [159, 159]]
|
[39, 159], [79, 159], [119, 159], [159, 159]]
|
||||||
|
@ -224,6 +227,7 @@ class TestCvMat_imageprocessing < OpenCVTestCase
|
||||||
refined_corners = mat.find_corner_sub_pix(corners, CvSize.new(3, 3), CvSize.new(-1, -1),
|
refined_corners = mat.find_corner_sub_pix(corners, CvSize.new(3, 3), CvSize.new(-1, -1),
|
||||||
CvTermCriteria.new(20, 0.03));
|
CvTermCriteria.new(20, 0.03));
|
||||||
assert_equal(expected.size, refined_corners.size)
|
assert_equal(expected.size, refined_corners.size)
|
||||||
|
assert(found)
|
||||||
expected.zip(refined_corners).each { |e, a|
|
expected.zip(refined_corners).each { |e, a|
|
||||||
assert_in_delta(e[0], a.x, 3.0)
|
assert_in_delta(e[0], a.x, 3.0)
|
||||||
assert_in_delta(e[1], a.y, 3.0)
|
assert_in_delta(e[1], a.y, 3.0)
|
||||||
|
|
Loading…
Add table
Reference in a new issue