def test_assert_find_marker_contours_does_not_modify_thresh(self): params = MarkerDetectPar.params thresh = cv2.adaptiveThreshold( self.gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 3, params[MarkerDetectPar.adaptiveThreshConstant]) thresh_copy = np.copy(thresh) MarkerDetectPar._find_marker_contours(thresh) np.testing.assert_equal(thresh, thresh_copy)
def test_find_marker_contours_equals_aruco_method(self): """ Tests find_marker_contours with various thresholded images. Note that candidate matrices are floats, and thus must be tested with allclose. However, contour matrices with ints should be tested with array_equal. :return: """ params = MarkerDetectPar.params aruco_params = (params[MarkerDetectPar.minMarkerPerimeterRate], params[MarkerDetectPar.maxMarkerPerimeterRate], params[MarkerDetectPar.polygonalApproxAccuracyRate], params[MarkerDetectPar.minCornerDistanceRate], params[MarkerDetectPar.minDistanceToBorder]) # thresh with winSize = 3 thresh_3 = cv2.adaptiveThreshold( self.gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 3, params[MarkerDetectPar.adaptiveThreshConstant]) test_contours_thresh_3 = MarkerDetectPar._find_marker_contours( thresh_3) true_contours_thresh_3 = aruco._findMarkerContours( thresh_3, *aruco_params) np.testing.assert_allclose(test_contours_thresh_3[0], true_contours_thresh_3[0]) try: np.testing.assert_array_equal(test_contours_thresh_3[1], true_contours_thresh_3[1]) except AssertionError: print( "_find_marker_contours: arrays not equal -- try per-element / per-row comparison" ) np.testing.assert_array_equal([ np.array_equal(a, b) for a, b in zip(test_contours_thresh_3[1], true_contours_thresh_3[1]) ], [True] * len(test_contours_thresh_3[1])) # thresh with winSize = 13 thresh_13 = cv2.adaptiveThreshold( self.gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY_INV, 13, params[MarkerDetectPar.adaptiveThreshConstant]) test_contours_thresh_13 = MarkerDetectPar._find_marker_contours( thresh_13) true_contours_thresh_13 = aruco._findMarkerContours( thresh_13, *aruco_params) np.testing.assert_allclose(test_contours_thresh_13[0], true_contours_thresh_13[0]) try: np.testing.assert_array_equal(test_contours_thresh_13[1], true_contours_thresh_13[1]) except AssertionError: print( "_find_marker_contours: arrays not equal -- try per-element / per-row comparison" ) np.testing.assert_array_equal([ np.array_equal(a, b) for a, b in zip( test_contours_thresh_13[1], true_contours_thresh_13[1]) ], [True] * len(test_contours_thresh_13[1]))