mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23:05 +04:00
Merge pull request #29252 from JonasPerolini:pr-aruco-bit-threshold-in-refine
Use validBitIdThreshold for Aruco refineDetectedMarkers #29252 The goal of this PR is to solve the issue raised by @vrabaud in https://github.com/opencv/opencv/pull/28289 (comment: https://github.com/opencv/opencv/pull/28289#discussion_r3355812646). **Issue:** `refineDetectedMarkers()` converted the extracted cell ratios with `convertTo(CV_8UC1)` (an implicit 0.5 threshold) before computing the code distance, ignoring `detectorParams.validBitIdThreshold`. **Solution:** Make the refine path consistent with the main detection path `Dictionary::identify`. **Changes:** - Add a `Dictionary::getDistanceToId()` overload that takes the float cell pixel ratio matrix and `validBitIdThreshold` (similar to how it's done for the `identify()` overload. - Move the per cell distance computation into a private `getDistanceToIdImpl` helper used by both `identify()` and the new overload of `getDistanceToId()` to avoid repetitions. - `refineDetectedMarkers()` now calls the new overload. **Tests:** - `CV_ArucoRefine.validBitIdThreshold`: a marker with one degraded cell is recovered at threshold 0.7 but not at 0.49. - `CV_ArucoDictionary.getDistanceToIdCellPixelRatio`: unit-tests both `getDistanceToId` overloads. All passed
This commit is contained in:
@@ -144,6 +144,32 @@ class aruco_objdetect_test(NewOpenCVTests):
|
||||
|
||||
self.assertEqual(dist, 0)
|
||||
|
||||
def test_getDistanceToId_cell_pixel_ratio(self):
|
||||
aruco_dict = cv.aruco.getPredefinedDictionary(cv.aruco.DICT_4X4_50)
|
||||
idx = 7
|
||||
valid_bit_id_threshold = 0.49
|
||||
bit_marker = np.array([[0, 1, 0, 1], [0, 1, 1, 1], [1, 1, 0, 0], [0, 1, 0, 0]], dtype=np.uint8)
|
||||
ratio_marker = bit_marker.astype(np.float32)
|
||||
|
||||
# Same marker as test_getDistanceToId, but passed as float cell ratios.
|
||||
dist = aruco_dict.getDistanceToId(ratio_marker, idx, True, valid_bit_id_threshold)
|
||||
self.assertEqual(dist, 0)
|
||||
|
||||
# A small drift stays within the threshold.
|
||||
accepted_ratio = ratio_marker.copy()
|
||||
accepted_ratio[0, 0] = 0.4
|
||||
dist = aruco_dict.getDistanceToId(accepted_ratio, idx, True, valid_bit_id_threshold)
|
||||
self.assertEqual(dist, 0)
|
||||
|
||||
# A full flip crosses the threshold and counts as one bad cell.
|
||||
erroneous_ratio = ratio_marker.copy()
|
||||
erroneous_ratio[0, 0] = 1.0 - erroneous_ratio[0, 0]
|
||||
dist = aruco_dict.getDistanceToId(onlyCellPixelRatio=erroneous_ratio,
|
||||
id=idx,
|
||||
allRotations=True,
|
||||
validBitIdThreshold=valid_bit_id_threshold)
|
||||
self.assertEqual(dist, 1)
|
||||
|
||||
def test_aruco_detector(self):
|
||||
aruco_params = cv.aruco.DetectorParameters()
|
||||
aruco_dict = cv.aruco.getPredefinedDictionary(cv.aruco.DICT_4X4_250)
|
||||
|
||||
Reference in New Issue
Block a user