What to do when a video cannot be read by cv2.VideoCapture

Thing you want to do

I want to load AVI format videos frame by frame using OpenCV from Python: blush:

Crashed problem

I called the read method of cv2.VideoCapture to read the frame of the video and drew it with cv2.imshow, but it turned black all over and was not displayed correctly: rage:

Image of the executed script


cap = cv2.VideoCapture('test.avi')
ret, frame = cap.read()
cv2.imshow('frame', frame)

The video can be played with other software.

Execution environment

Python settings

I installed Anaconda 3 on Windows10 (64bit) and built a virtual environment of Python 2.7. I installed libraries such as matplotlib, numpy, and pyqt in the virtual environment. In the following, the installation path of Anaconda is C: \ Anaconda, and the name of the virtual environment is py27. At this time, the virtual environment configuration file is saved in C: \ Anaconda \ envs \ py27.

The Python script is edited and executed in the jupyter notebook started from Anaconda.

Settings to call OpenCV from Python

Download the zip file containing the set of binaries for windows (for example, opencv3.3.0.zip) from the official OpenCV website and unzip it. Copy build \ python \ 2.7 \ x64 \ cv2.pyd in the unzipped zip file to C: \ Anaconda \ envs \ py27 \ Lib \ site-packages```. Now you can use the basic functions of OpenCV.

(Please tell me if there is a better way)

Solution

Check the following file in `\ build \ bin` in the zip file (opencv3.3.0.zip earlier) downloaded when you installed OpenCV.

Since this is a 64-bit environment, select ʻopencv_ffmpeg330_64.dll and copy it to C: \ Anaconda \ envs \ py27 \ Library \ bin`.

that's all.

Disclaimer

The content of this article may be inaccurate. We are not responsible for any damage caused by the contents of this article or its use.

References

[1] https://stackoverflow.com/questions/11699298/opencv-2-4-videocapture-not-working-on-windows

Recommended Posts

What to do when a video cannot be read by cv2.VideoCapture
What to do if pip cannot be installed
What to do when gdal_merge creates a huge file
[Ubuntu 18.04 LTS] What to do when the screen resolution cannot be selected [NVIDIA]
What to do when "cannot import name xxx" [Python]
What to do if pvcreate produces a lot of WARNING and cannot be created
What to do if the package dependency cannot be repaired
What to do when a Remove Error occurs when updating conda
What to do when Ubuntu crashes
What to do if ʻObject arrays cannot be loaded when allow_pickle = False` occurs in numpy.load ()
[AWS] What to do when the ping command causes a "timeout"
What to do if PyAudio cannot be installed on Python 3.7, 3.8, 3.9 on Windows
[Memorandum] What to do when a warning appears after executing pip list
What to do if fprintd requires a password when registering your fingerprint
What to do when a warning message is displayed in pip list
What to do when "OS Error: [WinError 126] The specified module cannot be found" appears in import torch
What to do if mod_fcgid cannot resolve UnicodeEncodeError
What to do when PermissionError of tempfile.mkstemp occurs
What to do when "TypeError: must be string, not int…" appears when using strptime
What to do when a warning appears around Python integration in Neovim's CheckHealth
What to do if abort is displayed when inputting camera video in OpenCV
What to do when you want to receive files from a Windows client remotely
What to do if you are told "Import Error: cannot import name'HTTPSHandler'" when building a virtual environment using virtualenv
When writing a test using DB with django, you may be able to do it faster by using `setUpTestData ()`
curl: (60) What to do when Issuer certificate is invalid.
What to do when is not in the sudoers file.This incident will be reported.
What to do if you get a memory error when converting from PySparkDataFrame to PandasDataFrame
What to do when raise ValueError, "unsupported hash type"
What to do if a UnicodeDecodeError occurs in pip
What to do when "Type Error: must be _socket.socket, not socket" appears on GAE
What to do when you can't bind CaboCha to Python
What to do when a Missing artifact occurs in a jar that is not defined in pom.xml
What to do if you get a Cannot retrieve metalink for repository error in yum
[AWS] What to do when you want to pip with Lambda
How to switch the configuration file to be read by Python
What to do if pip gives a DistributionError in Homebrew
What to do when PyCharm font is strange or garbled
Record of actions to be taken when google_image_download cannot be used
What to do when Unalignable boolean Series provided as indexer
ValueError: shape mismatch: objects cannot be broadcast to a single shape
What to do if a 0xC0000005 error occurs in tf.train.start_queue_runners ()
What to do when an error occurs with import _ssl
Be careful when assigning Series as a column to pandas.DataFrame
What to do if package installation fails when deploying to heroku
What to do when "SSL: CERTIFICATE_VERIFY_FAILED _ssl.c: 1056" appears in Python
OSError: [Errno 40] What to do when Message too long appears
What to do when "Invalid HTTP_HOST header" appears in Django
ImportError: No module What to do when you are told
When USB cannot be formatted
When pydub cannot be installed
What to do if you get angry with'vertices' must be a 2D list ... in matplotlib arrow
What to do when a part of the background image becomes transparent when the transparent image is combined with Pillow
What to do if you get a must override `get_config` error when trying to model.save in Keras
What to do if you get a minus zero in Python
[Beanstalk] What to do when an error occurs with import uuid
What to do when the jupyterlab extension settings are not reflected
What to do if you get a UnicodeDecodeError with pip install
What to do if Insecure Platform Warning appears when running Python
What to do when you get "I can't see the site !!!!"
What to do when UnicodeDecodeError occurs during read_csv in pandas (pd.read_table ())
When you want to sort a multidimensional list by multiple lines