#程序
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('D:/download/PyCharm/PycharmProjects/5.1.jpg')
img = cv2.medianBlur(img,5)
ret,th1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
th2 = cv2.adaptiveThreshold(img,255,
cv2.ADAPTIVE_THRESH_MEAN_C,
cv2.THRESH_BINARY,11,2)
th3 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2)
titles = ['original image' , 'global thresholding ','Adaptive mean thresholding',
'adaptive gaussian thresholding']
images = [img,th1,th2,th3]
for i in range(4):
plt.subplot(2, 2, i+1),plt.imshow(images,'gray')
plt.title(titles)
plt.xticks([]),plt.yticks([])
plt.show()
报错提示:Traceback (most recent call last): File "D:/download/PyCharm/PycharmProjects/1049.py", line 11, in <module> cv2.THRESH_BINARY,11,2)cv2.error: OpenCV(3.4.3) C:\projects\opencv-python\opencv\modules\imgproc\src\thresh.cpp:1524: error: (-215:Assertion failed) src.type() == CV_8UC1 in function 'cv::adaptiveThreshold'不得其解,求助大佬!
|