opencv: cv::findDecoder imread_: can't open/read file: check file path/integrity

System information (version)
  • OpenCV => 4.5.5
  • Operating System / Platform => Windows 64 Bit/Anaconda 4.1.2
  • Compiler => Spyder/anaconda prompt
Detailed description

Opencv doesnt open videos. It works normally with static images, but cv2.VideoCapture() fails. The error: [ WARN:0@0.211] global C:\build\master_winpack-build-win64-vc15\opencv\modules\imgcodecs\src\loadsave.cpp (239) cv::findDecoder imread_(‘cinto.mp4’): can’t open/read file: check file path/integrity

where ‘cinto.mp4’ is the file i’m trying to read. The problem is not with the file or the file location as i’m running the code in the same path as the video.

Steps to reproduce
  import cv2
  file_name = 'cinto.mp4'
  vcap = cv2.VideoCapture(file_name)
  if vcap.isOpened():
    width  = int(vcap.get(cv2.CAP_PROP_FRAME_WIDTH))   # float `width`
    height = int(vcap.get(cv2.CAP_PROP_FRAME_HEIGHT))  # float `height`
    fps =  vcap.get(cv2.CAP_PROP_FPS)
  else:
    print("Error opening the video")
    return -1

The code above prints: Error opening the video

[ WARN:0@0.211] global C:\build\master_winpack-build-win64-vc15\opencv\modules\imgcodecs\src\loadsave.cpp (239) cv::findDecoder imread_(‘cinto.mp4’): can’t open/read file: check file path/integrity

I tried to install opencv with conda and couldn’t, so i tried with opencv version. I also tried with the Windows Release downloaded in https://opencv.org/releases/

Issue submission checklist
  • I report the issue, it’s not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 10
  • Comments: 31

Most upvoted comments

You can add below lines before initializing file_name: import os os.chdir(folder_address_which_contain_your_file)

It hope this helps.

i have the same issue when i am working on a project THE SOLUTION you file is not in the same directory you are calling try to check your file location on your system and check the directory you are calling

I was able to solve mine by saving the image in the folder of the program

I have found the root cause of the issue. It is because when you are calling the VideoCapture() with file_name, there is no such file in your current directory with same file_name. It helped me. So, I think you can close this issue now after trying my suggestion.

It was the first thing I tried. It isn’t that.

None of the solutions here worked for me… Please help. I ve tried everything

@Secxnd Hey, could you elaborate on the fix? I am facing the same issue in C++ on windows OS. I am using Visual Studio 2022, if that helps.

UPDATE: What worked for me was changing the mode to Release Mode and suddenly it started working. Did not dive deep into the root cause but this was the quick fix for me.

I had the same issue -> only working solution was to not use the absolute path, but the program path.

My directory: program program/main.py program/data program/images program/images/image1.jpg

img = cv2.imread(‘C:/Users/user1/Projects/program/data/images/image1.jpg’) -> won’t work

img = cv2.imread(‘data/images/image1.jpg’) -> works just fine

I would guess that cv2.imread function runs “os.getcwd()” function inside itself and thus you need only give it the path from program file perspective

I am running Ubunutu 22.04. I did not find the root of the issue but I found a pattern: In the terminal you must to be inside the same folder where your python code is located and the image you want to load can be anywhere in the project.

Ex: We have the root path of the project. Let’s say that I have a folder myFolderTest and inside this folder I have a pic.jpeg that I want to load and a loadimage.py file.

In the terminal if I run from the root $ python3 myFolderTest/loadimage.py it will throw the error ... can't open/read file: check file path/integrity.

In another hand if I go to the folder that contains the python file I will have no issue: .../myFolderTest $ python3 loadimage.py

If I put the picture outside or inside the folder myFolderTest I just need to refer it in the fucntion it self img = cv2.imread('../pictures/pic1.png', cv2.IMREAD_COLOR) but I must to be inside the same folder that called the python file.

Have the same problem if my path (where the program is or file_name name) include any non-ascii character.

Even I am facing the same issue. Till now, I don’t have any lead on this. I hope someone give some insight on this issue.

POSSIBLE SOLUTION:

My directory: program program/main.py program/images program/images/image1.png

When running main.py it threw that error. I changed the location from “./images/image1.png” to ./program/images/image1.png" in the code and it worked!

This may not be the issue for some but it may be for others. My program thinks it is in the parent directory for some reason… Possibly due to the way I opened the file in VS Code.

Provide relative or absolute path of the image. It should work fine.