When importing the PyAv module, I am unable to show an image with opencv using imshow()
Code without the PyAv module (works as expected)
import cv2
img = cv2.imread("test_image.jpeg")
cv2.imshow('image', img)
cv2.waitKey(0)
Code with the import (doesn't work, just hangs)
import cv2
import av
img = cv2.imread("test_image.jpeg")
cv2.imshow('image', img)
cv2.waitKey(0)
OS: Linux arch 5.18.3-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 09 Jun 2022 16:14:10 +0000 x86_64 GNU/Linux
Am I doing something wrong or is this a (un-)known issue?
So it is a known issue, mentioned here, but it is possible to use the workaround mentioned in the post, here is a quick rundown of how I did it:
NOTE: Do this in a python virtualenv or you might run into problems in the long run
git clone --recursive https://github.com/opencv/opencv-python.git and run this script (If this fails, because the path '/tmp/vendor/include doesn't exists, just create it like this mkdir -p /tmp/vendor/include)make -j4 and let it buildpython_loader folder and run python3 setup.py develop and you are done installing :)Instead of having to compile from source, you can instead uninstall pyav and reinstall it with:
pip install av --no-binary av
This installs PyAV without FFmpeg and defaults to using your system's already available FFmpeg (likely OpenCV's). This answer was suggested by the people at PyAV reference. This is assuming that you already have FFmpeg (likely from OpenCV).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With