Python Opencv morphological closing gives src data type = 0 is not supported
Asked Answered
S

2

9

I'm trying to morphologically close a volume with a ball structuring element created by the function SE3 = skimage.morphology.ball(8). When using closing = cv2.morphologyEx(volume_start, cv2.MORPH_CLOSE, SE) it returns TypeError: src data type = 0 is not supported Do you know how to solve this issue? Thank you

Saundra answered 10/11, 2015 at 11:13 Comment(1)
Distantly related: #30990415 #25137663Hypnotist
C
14

Make sure volume_start is dtype=uint8. You can convert it with volume_start = np.array(volume_start, dtype=np.uint8).

Or nicer: volume_start = volume_start.astype(np.uint8)

Croupier answered 27/5, 2017 at 12:33 Comment(0)
S
0

The same error occurred to me while calling the erode function on a binarized image that I binarized (from a grayscale image of 0 to 255 values) like this:

bin_img = grayscale_img > 125

I guess the > operator "swallowed" the type, or changed it to the openCV's type of code 0.

I solved it by doing the binarization like this:

ret, bin_img = cv2.threshold(grayscale, 125, 255, cv2.THRESH_BINARY)

ret is the threshold value (125 in this case), and bin_img is the resulting binary image.

Sophrosyne answered 14/2, 2018 at 21:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.