我正在研究预训练的 vgg16 模型,因为我需要输入图像文件的大小为(224,224,3)。
我正在处理的代码是:
from tensorflow.keras.preprocessing import image
import cv2
import matplotlib.pyplot as plt
img = image.load_img('abc.jpg',target_size=(224,224))
img = image.img_to_array(img)
print(img.shape)
## output : (224,224,3)
img_grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#plt.imshow(img_grey)
th3 = cv2.adaptiveThreshold(img_grey,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2)
plt.figure(figsize=(20,10))
plt.imshow(th3)
error Traceback (most recent call last)
<ipython-input-88-2a8a27b965ed> in <module>
17 #plt.imshow(img_grey)
18
---> 19 th3 = cv2.adaptiveThreshold(img_grey,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2)
20 plt.figure(figsize=(20,10))
21 plt.imshow(th3)
error: OpenCV(4.1.0) /io/opencv/modules/imgproc/src/thresh.cpp:1627: error: (-215:Assertion failed) src.type() == CV_8UC1 in function 'adaptiveThreshold'
帮助我解决问题。