diff --git a/plantcv/plantcv/transform/detect_color_card.py b/plantcv/plantcv/transform/detect_color_card.py index 3fe20c072..ac6e294a2 100644 --- a/plantcv/plantcv/transform/detect_color_card.py +++ b/plantcv/plantcv/transform/detect_color_card.py @@ -292,6 +292,14 @@ def _macbeth_card_detection(rgb_img, **kwargs): new_rect = cv2.minAreaRect(np.array(centers)) # Get the corners of the rectangle box_points = cv2.boxPoints(new_rect).astype("float32") + # previously the boxpoints (corners of box) started from the top left and proceeded clockwise around the image. + # between opencv 4.12.0 and 4.13.0 there is an unexplained change to start boxPoints from + # the bottom right of the image, so now we have to find the bottom right point and make sure + # that it is in the bottom right + bottom_right_corner_index = np.argsort(-box_points.sum(axis=1))[0] + # if the largest sum (bottom right corner of box) is the first element then sort the elements properly. + if bottom_right_corner_index == 0: + box_points = box_points[[2, 3, 0, 1]] # Calculate the perspective transform matrix from the minimum area rectangle m_transform = cv2.getPerspectiveTransform(box_points, corners.astype("float32")) # Transform the chip centers using the perspective transform matrix