Skip to content

How to tell if pcv.find_objects() didn't find any contours? #820

Answered by nfahlgren
Tronheim asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @Tronheim, great question. There are at least two approaches, depending on what works best for you.

When pcv.find_objects does not find any contours, it returns an empty list (contours is otherwise a list of contours) and None (hierarchy). So you could check the length of the contours list, set up a conditional on whether contours is True/False (not empty/empty), etc.

Alternatively, I think a somewhat more robust approach is to check later in the workflow. This is because pcv.find_objects may find contours that end up getting filtered out by pcv.roi_objects later. Or in other words, find_objects is only empty when no contours are found (no background) but roi_objects is empty when no p…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Tronheim
Comment options

Answer selected by Tronheim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants