warning can't open/read file: check file path/integrity

Question:

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:aopencv-pythonopencv-pythonopencvmodulesimgprocsrcresize.cpp:4052: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'

and this warning [ WARN:[email protected]] global D:aopencv-pythonopencv-pythonopencvmodulesimgcodecssrcloadsave.cpp (239) cv::findDecoder imread_('dataset/trainApple/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

Asked By: awatif

||

Answers:

file = dir + "/" + str(x) + ".jpg"

try to replace this line with :

file = dir + "" + str(x) + ".jpg"

the / not correct

the correct is

Answered By: Mr Dream

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

Answered By: Riz.Khan

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.enter image description here

Answered By: Md.Rakibuz Sultan

for me, my file path have ‘n’ in the end. use os.path.exist check, not exist

Answered By: silva

Make sure that the file name does not contain any special characters, OpenCV seems to be quite sensitive here.

For me the problem was that it contained some umlauts (ä, ö, ü).

Answered By: das Keks

in my case it was the filename extension that caused problems. Check whether your png/img/bmp is a png/img/bmp or something else 😉

Answered By: Tim Bretschneider

Check if such a file really exists. If it gives an error, put it at the same address as the image or the file, for example:
the location of your file is C:Desktop with this name polarbear.jpg. The location of the file where you write the code is C:DesktopFilesPython
Let it be called kod.py. The code will give an error because your file and your code are not at the same address. Try putting the file and the code at the same address. My file:
C:DesktopFilesPythonpolarbear.jpg
My code:
C:DesktopFilesPythoncode.py if you do this solution do not write all of the path just the file name. Example:
"polarbear.jpg" Same thing happend to me also I looked for every solution and I couldnt fix it when I was messing around I found the problem. It realy works

Answered By: Aybar
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.