Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: src data type = 17 is not supported

Tags:

python

opencv

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

like image 994
Law.X Avatar asked Jan 19 '17 02:01

Law.X


1 Answers

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.

like image 137
Miki Avatar answered Oct 26 '22 18:10

Miki