Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
511 views
in Technique[技术] by (71.8m points)

python - TypeError: src data type = 17 is not supported

I'm now in a program try to change pictures from normal to binaryzation.So i use opencv on python, but when i finish my problem in my home carry my code to my office it come up with a unknown error.So i come to here ,looking for help.

from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import cv2
im = Image.open('card.jpg')
img = np.array(im)
if img.ndim == 3:
    img = img[:, :,0]
    plt.gray()
ret, thresh1 = cv2.threshold(img, 50, 255, cv2.THRESH_BINARY)


plt.subplot(222)
plt.imshow(thresh1)
plt.show()

The traceback is

Traceback (most recent call last): File "D:/tensorflow/opencv.py", line 12, in ret, thresh1 = cv2.threshold(img, 50, 255, cv2.THRESH_BINARY) TypeError: src data type = 17 is not supported

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can find a list of OpenCV types here.

type = 17 means that your image is a CV_8SC3, aka a 3 channel matrix of char. However, threshold accepts only

(single-channel, 8-bit or 32-bit floating point).

which means that the type must be either CV_8UC1 or CV_32FC1.

Check shape and dtype of your img, and adjust img as required.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...