Modes other than RETR_FLOODFILL and RETR_CCOMP support only CV_8UC1 images #16282
-
I try to get the contours of the detected objects in an image but I get this unspecified error:
My code:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
👋 Hello @johnlockejrr, thank you for reaching out about your issue with contour detection 🚀! This is an automated response, but rest assured, an Ultralytics engineer will assist you soon. The error you're encountering indicates a mismatch in the image type expected by Here's how you can adjust your code to fix this issue: Solution:Ensure the # Assuming 'resized' needs to be a binary image (0 and 255)
# Convert the mask to a binary image
resized = (resized > 0.5).astype(np.uint8) * 255 Updated Code:# Mask
m = mask.data.cpu().numpy()
resized = cv2.resize(m, (img.shape[1], img.shape[0]), interpolation = cv2.INTER_AREA)
# Convert resized mask to binary image
resized_binary = (resized > 0.5).astype(np.uint8) * 255
contours, _ = cv2.findContours(resized_binary, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnt = []
area = 0
for c in contours:
a = cv2.contourArea(c)
if a > area:
cnt = c
area = a
roi = cv2.drawContours(roi, [cnt], -1, colors[category], -1) Tips:
If you have more questions or need further clarification, feel free to provide additional details. Join our community for more support: Happy coding! 🖥️ |
Beta Was this translation helpful? Give feedback.
-
@johnlockejrr you don't need any of that code to get the contour coordintes, just |
Beta Was this translation helpful? Give feedback.
@johnlockejrr you don't need any of that code to get the contour coordintes, just
results[0].masks.xy
.