10

I'm trying to find contours in a binary image which is a numpy array

a = np.array(np.random.rand(1024,768),dtype='float32')    
_, t2 = cv2.threshold(a,127,255,0)
im2, contours, hierarchy = cv2.findContours(t2,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)

When I try to run that code I get this error

OpenCV Error: Unsupported format or combination of formats
([Start]FindContours supports only CV_8UC1 images when 
mode != CV_RETR_FLOODFILL otherwise supports CV_32SC1 images only)
in cvStartFindContours

1 Answer 1

4

As the error message states - the only format supported, when the mode is not CV_RETR_FLOODFILL, is CV_8UC1 => single channel 8 bit, unsigned integer matrix. When the mode is CV_RETR_FLOODFILL, the only supported format is CV_32SC1 - 32 bit signed...

Since you are passing array of float32, it is CV_32FC1 - 32 bit, floating, which is not supported. You have to use array of integer.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks j-kaspar, that fixs the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.