error: (-215:Assertion failed) size.width>0 && size.height>0 in function ‘cv::imshow‘

import cv2 as cv

import numpy as np

#Read images

img=cv.imread(r'E:\Downloaded\pexels\The sea21471.jpeg',1)

#Get the image's aspect information

sp=img.shape

length=sp[1]

heighth=sp[0]

print('width:{},height:{}'.format(length,height)) of the loaded image

#Display window and picture

cv.namedWindow('original image')

cv.imshow('original image',img)

#convert to grayscale image

img2=cv.cvtColor(img,cv.COLOR_BGR2GRAY)

cv.namedWindow('after conversion')

cv.imshow('after conversion',img2)

#image binarization

cv.threshold(img,280,500,0,img)

cv.namedWindow('image binarization')

cv.imshow('image binarization',img2)

# Set the window wait time, 0 means always display

cv.waitKey(0)

#Manual memory release

cv.destroyAllWindows()

After Baidu saw the answer to a similar question, it was because the path was wrong, that is, the picture could not be found, so it reported an error. After modifying the path, the picture was successfully displayed, and the effect was as follows:

Undertake MATLAB, Python and C + + programming, machine learning, computer vision theory implementation and guidance, undergraduate and master can, salted fish trading,

Read More: