cv2.error: OpenCV(3.4.3) C:projectsopencv-pythonopencvmoduleshighguisrcwindow.cpp:356: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'
import cv2 as cv
from matplotlib import pyplot as plt
# Draw a histogram
def hist_image(image):
color = ('blue', 'green', 'red')
for i, color in enumerate(color):
hist = cv.calcHist([image], [i], None, [256], [0, 256])
plt.plot(hist, color=color)
plt.xlim([0, 256])
plt.show()
src = cv.imread(r'D:\pic\图片.jpg')
cv.namedWindow('y', cv.WINDOW_NORMAL)
cv.imshow('y', src)
hist_image(src)
cv.waitKey(0)
cv.destroyAllWindow()
The reason is that the picture is not read correctly
Please test if the image is loaded correctly first
In the wrong attitude, change the name of the photo file to English and it will be OK!