Home > front end >  Can't show image with opencv when importing av
Can't show image with opencv when importing av

Time:06-17

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?

CodePudding user response:

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

  1. Find which version of ffmpeg PyAv uses (currently it's 'ffmpeg-4.4.1-5') and download the exact ffmpeg version here
  2. Clone the python-opencv github repo like this 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)
  3. After this is done you can check in the output if the correct ffmpeg version is selected
  4. If everything looks correct, you can build it with this command make -j4 and let it build
  5. Finally cd into the python_loader folder and run python3 setup.py develop and you are done installing :)
  • Related