'warning can't open/read file: check file path/integrity
images_per_class = 80
fixed_size = tuple((500, 500))
train_path = "dataset/train"
train_labels = os.listdir(train_path)
for training_name in train_labels:
dir = os.path.join(train_path, training_name)
current_label = training_name
for x in range(1,images_per_class+1):
# get the image file name
file = dir + "/" + str(x) + ".jpg"
# read the image and resize it to a fixed-size
image = cv2.imread(file)
image = cv2.resize(image, fixed_size)
when i run this code it appeare this error
error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\resize.cpp:4052: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
and this warning [ WARN:[email protected]] global D:\a\opencv-python\opencv-python\opencv\modules\imgcodecs\src\loadsave.cpp (239) cv::findDecoder imread_('dataset/train\Apple/1.jpg'): can't open/read file: check file path/integrity
i dont have probleme with installation of opencv because i use it before andwith another code it fonctionne any help please
Solution 1:[1]
file = dir + "/" + str(x) + ".jpg"
try to replace this line with :
file = dir + "\" + str(x) + ".jpg"
the / not correct
the correct is \
Solution 2:[2]
Dears, for me the issue was related to filename extension. I put the extension .JPEG whereas the actual extension was .jpg. Correcting the extension cleared the warning. thanks
Solution 3:[3]
Recently I have faced the same issue, the problem was the file was not exist there. I realise file names could also be a problem.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Mr Dream |
Solution 2 | Riz.Khan |
Solution 3 | Md.Rakibuz Sultan |