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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With