From 1f44968b60c465f3b749baa7b802d8d6746c187d Mon Sep 17 00:00:00 2001 From: Josh Sumner <51797700+joshqsumner@users.noreply.github.com> Date: Thu, 29 Jan 2026 16:05:22 -0600 Subject: [PATCH 1/2] reorder box points if opencv shuffled them around --- plantcv/plantcv/transform/detect_color_card.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plantcv/plantcv/transform/detect_color_card.py b/plantcv/plantcv/transform/detect_color_card.py index 3fe20c072..84b80a419 100644 --- a/plantcv/plantcv/transform/detect_color_card.py +++ b/plantcv/plantcv/transform/detect_color_card.py @@ -292,7 +292,15 @@ 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") - # Calculate the perspective transform matrix from the minimum area rectangle + # 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 new_centers = cv2.transform(np.array([centers]), m_transform)[0][:, 0:2] From 9506b322bac7bdec3e0ba03d63549db47a639d3c Mon Sep 17 00:00:00 2001 From: Josh Sumner <51797700+joshqsumner@users.noreply.github.com> Date: Thu, 29 Jan 2026 16:12:17 -0600 Subject: [PATCH 2/2] deepsource --- plantcv/plantcv/transform/detect_color_card.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plantcv/plantcv/transform/detect_color_card.py b/plantcv/plantcv/transform/detect_color_card.py index 84b80a419..ac6e294a2 100644 --- a/plantcv/plantcv/transform/detect_color_card.py +++ b/plantcv/plantcv/transform/detect_color_card.py @@ -300,7 +300,7 @@ def _macbeth_card_detection(rgb_img, **kwargs): # 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 + # 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 new_centers = cv2.transform(np.array([centers]), m_transform)[0][:, 0:2]