Skip to content Skip to sidebar Skip to footer

FindContours Support Only 8uC1 And 32sC1 Images

i hava problem in fire detection my code is : ret, frame = cap.read() lab_image = cv2.cvtColor(frame, cv2.COLOR_BGR2LAB) L , a , b = cv2.split(lab_image) ret,thresh_L = cv2.thres

Solution 1:

img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

Use this line on your image to convert it from BGR to grayscale (8UC1) format before finding contours. FindContours function only supports a grayscale image format.


Solution 2:

In my solution I had to convert the dtype into uint8.

Yes, my image was binary image(single channel), however in my code somehow the thresh_image was changed into float32 data type. But cv2.findContours() cannot handle float32.

So I had to explicitly convert float32 --> uint8.

thresh_image = thresh_image.astype(np.uint8)

Solution 3:

For completion, the 8UC1 format is 8 byte, unsigned, single channel. In addition to cv2 grayscale, single-channel uint8 format will also be valid, in case anyone is building the image outside of cv2 functions and encounters this error.


Solution 4:

The documention of findContours is clearly saying that it can afford to take single channel images as inputs(i.e 8uc1 and 32sc1) But you are sending 3 channel image.here is the documentation of findcontours http://docs.opencv.org/2.4/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html#findcontours


Post a Comment for "FindContours Support Only 8uC1 And 32sC1 Images"