conda-forge / opencv-feedstock

A conda-smithy repository for opencv.
BSD 3-Clause "New" or "Revised" License
65 stars 60 forks source link

imshow failing on raspberry pi 64 bit OS (linux-aarch64) #305

Closed johnholman closed 2 years ago

johnholman commented 2 years ago

Solution to issue cannot be found in the documentation.

Issue

Trying to use opencv on 8GB raspberry pi 4 running PIOS 64 bit (Debian bullseye). Installed using mamba-forge as

mamba create -n opencv
mamba activate opencv
mamba install qt opencv

Running simple test script that reads an image file and then attempts to display it with imshow():

import cv2 as cv
img = cv.imread(cv.samples.findFile("jurassic_park.png"))
print(f'image size {img.shape}')    
cv.imshow("Display window", img)
k = cv.waitKey(0)

Result:

  File "/home/pi/src/opencv/imshow.py", line 8, in <module>
    cv.imshow("Display window", img)
cv2.error: OpenCV(4.5.5) /home/conda/feedstock_root/build_artifacts/libopencv_1647515468288/work/modules/highgui/src/window.cpp:1268: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage'

I hoped this would work as https://github.com/conda-forge/opencv-feedstock/pull/301 suggests that qt support has been merged but perhaps I misunderstand. I did notice that qt was not installed as a dependency hence the explicit installation.

NOTE (added next day) Still simpler test which doesn't require a test image is

import cv2 cv2.waitKey(0)

which produces similar error:

cv2.error: OpenCV(4.5.5) /home/conda/feedstock_root/build_artifacts/libopencv_1647515468288/work/modules/highgui/src/window.cpp:1334: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvWaitKey'

Installed packages

# packages in environment at /home/pi/mambaforge/envs/opencv:
#
# Name                    Version                   Build  Channel
_openmp_mutex             4.5                       1_gnu    conda-forge
alsa-lib                  1.2.3                h516909a_0    conda-forge
bzip2                     1.0.8                hf897c2e_4    conda-forge
c-ares                    1.18.1               hf897c2e_0    conda-forge
ca-certificates           2021.10.8            h4fd8a4c_0    conda-forge
cairo                     1.16.0            h007064d_1010    conda-forge
dbus                      1.13.6               h12b9eeb_3    conda-forge
expat                     2.4.7                ha18d298_0    conda-forge
ffmpeg                    4.3.2                hf67a8e1_3    conda-forge
font-ttf-dejavu-sans-mono 2.37                 hab24e00_0    conda-forge
font-ttf-inconsolata      3.000                h77eed37_0    conda-forge
font-ttf-source-code-pro  2.038                h77eed37_0    conda-forge
font-ttf-ubuntu           0.83                 hab24e00_0    conda-forge
fontconfig                2.13.96              h856ede2_2    conda-forge
fonts-conda-ecosystem     1                             0    conda-forge
fonts-conda-forge         1                             0    conda-forge
freeglut                  3.2.2                h01db608_1    conda-forge
freetype                  2.10.4               hdf53a3c_1    conda-forge
gettext                   0.19.8.1          h6edf1e2_1008    conda-forge
gmp                       6.2.1                h7fd3ca4_0    conda-forge
gnutls                    3.6.13               h5fb5790_1    conda-forge
graphite2                 1.3.13            h7fd3ca4_1001    conda-forge
gst-plugins-base          1.18.5               h227fc8a_3    conda-forge
gstreamer                 1.18.5               h01406a2_3    conda-forge
harfbuzz                  4.0.1                hefe178f_0    conda-forge
hdf5                      1.12.1          nompi_h7bde11e_104    conda-forge
icu                       69.1                 h3621d8e_0    conda-forge
jasper                    2.0.33               h5ced176_0    conda-forge
jbig                      2.1               hf897c2e_2003    conda-forge
jpeg                      9e                   h3557bc0_0    conda-forge
keyutils                  1.6.1                h4e544f5_0    conda-forge
krb5                      1.19.3               h7c456eb_0    conda-forge
lame                      3.100             hf897c2e_1001    conda-forge
ld_impl_linux-aarch64     2.36.1               h02ad14f_2    conda-forge
lerc                      3.0                  h01db608_0    conda-forge
libblas                   3.9.0           13_linuxaarch64_openblas    conda-forge
libcblas                  3.9.0           13_linuxaarch64_openblas    conda-forge
libclang                  13.0.1          default_hf9dac01_0    conda-forge
libcurl                   7.82.0               h8fd98b7_0    conda-forge
libdeflate                1.10                 hf897c2e_0    conda-forge
libedit                   3.1.20191231         he28a2e2_2    conda-forge
libev                     4.33                 h516909a_1    conda-forge
libevent                  2.1.10               h6aed413_4    conda-forge
libffi                    3.4.2                h3557bc0_5    conda-forge
libgcc-ng                 11.2.0              hf1cc4e7_14    conda-forge
libgfortran-ng            11.2.0              he9431aa_14    conda-forge
libgfortran5              11.2.0              h440fb59_14    conda-forge
libglib                   2.70.2               hde3fb6c_4    conda-forge
libglu                    9.0.0             he1b5a44_1001    conda-forge
libgomp                   11.2.0              hf1cc4e7_14    conda-forge
libiconv                  1.16                 h6dd45c4_0    conda-forge
liblapack                 3.9.0           13_linuxaarch64_openblas    conda-forge
liblapacke                3.9.0           13_linuxaarch64_openblas    conda-forge
libllvm13                 13.0.1               hb2805f8_2    conda-forge
libnghttp2                1.47.0               h75cb1c7_0    conda-forge
libnsl                    2.0.0                hf897c2e_0    conda-forge
libogg                    1.3.4                h3557bc0_1    conda-forge
libopenblas               0.3.18          pthreads_h775ce2d_0    conda-forge
libopencv                 4.5.5            py31h802d7a1_5    conda-forge
libopus                   1.3.1                hf897c2e_1    conda-forge
libpng                    1.6.37               hbd635b3_2    conda-forge
libpq                     14.2                 h29fb33b_0    conda-forge
libprotobuf               3.19.4               h469bdbd_0    conda-forge
libssh2                   1.10.0               h1ab2c7b_2    conda-forge
libstdcxx-ng              11.2.0              h0d0a5bb_14    conda-forge
libtiff                   4.3.0                hdea21e4_3    conda-forge
libuuid                   2.32.1            hf897c2e_1000    conda-forge
libvorbis                 1.3.7                h01db608_0    conda-forge
libwebp-base              1.2.2                hf897c2e_1    conda-forge
libxcb                    1.13              h3557bc0_1004    conda-forge
libxkbcommon              1.0.3                he09c752_0    conda-forge
libxml2                   2.9.12               h1e2ce75_1    conda-forge
libzlib                   1.2.11            hb9de7d4_1013    conda-forge
lz4-c                     1.9.3                h01db608_1    conda-forge
mysql-common              8.0.28               h8af1aa0_0    conda-forge
mysql-libs                8.0.28               ha3f2873_0    conda-forge
ncurses                   6.3                  h01db608_0    conda-forge
nettle                    3.6                  ha0d5d3d_0    conda-forge
nspr                      4.32                 h01db608_0    conda-forge
nss                       3.74                 hdd3d7a4_0    conda-forge
numpy                     1.22.3          py310hd22b2ba_0    conda-forge
opencv                    4.5.5            py31hbbe02a8_5    conda-forge
openh264                  2.1.1                h469bdbd_0    conda-forge
openssl                   1.1.1l               hf897c2e_0    conda-forge
pcre                      8.45                 h01db608_0    conda-forge
pip                       22.0.4             pyhd8ed1ab_0    conda-forge
pixman                    0.40.0               hb9de7d4_0    conda-forge
pthread-stubs             0.4               hb9de7d4_1001    conda-forge
py-opencv                 4.5.5            py31h7d5ade6_5    conda-forge
python                    3.10.2          he7f7bba_4_cpython    conda-forge
python_abi                3.10                    2_cp310    conda-forge
qt                        5.12.9               hb57a898_5    conda-forge
readline                  8.1                  h1a49cc3_0    conda-forge
setuptools                60.10.0         py310hbbe02a8_0    conda-forge
sqlite                    3.37.1               hc74f5b8_0    conda-forge
tk                        8.6.12               hd8af866_0    conda-forge
tzdata                    2022a                h191b570_0    conda-forge
wheel                     0.37.1             pyhd8ed1ab_0    conda-forge
x264                      1!161.3030           hf897c2e_1    conda-forge
xorg-fixesproto           5.0               h3557bc0_1002    conda-forge
xorg-inputproto           2.3.2             h3557bc0_1002    conda-forge
xorg-kbproto              1.0.7             h3557bc0_1002    conda-forge
xorg-libice               1.0.10               h3557bc0_0    conda-forge
xorg-libsm                1.2.3             h965e137_1000    conda-forge
xorg-libx11               1.7.2                h3557bc0_0    conda-forge
xorg-libxau               1.0.9                h3557bc0_0    conda-forge
xorg-libxdmcp             1.1.3                h3557bc0_0    conda-forge
xorg-libxext              1.3.4                h3557bc0_1    conda-forge
xorg-libxfixes            5.0.3             h3557bc0_1004    conda-forge
xorg-libxi                1.7.10               h3557bc0_0    conda-forge
xorg-libxrender           0.9.10            h3557bc0_1003    conda-forge
xorg-renderproto          0.11.1            h3557bc0_1002    conda-forge
xorg-xextproto            7.3.0             h3557bc0_1002    conda-forge
xorg-xproto               7.0.31            h3557bc0_1007    conda-forge
xz                        5.2.5                h6dd45c4_1    conda-forge
zlib                      1.2.11            hb9de7d4_1013    conda-forge
zstd                      1.5.2                h41fb7a4_0    conda-forge

Environment info

(opencv) pi@raspberrypi:~/src/opencv $ conda info

     active environment : opencv
    active env location : /home/pi/mambaforge/envs/opencv
            shell level : 2
       user config file : /home/pi/.condarc
 populated config files : /home/pi/mambaforge/.condarc
          conda version : 4.11.0
    conda-build version : not installed
         python version : 3.9.10.final.0
       virtual packages : __linux=5.10.103=0
                          __glibc=2.31=0
                          __unix=0=0
                          __archspec=1=aarch64
       base environment : /home/pi/mambaforge  (writable)
      conda av data dir : /home/pi/mambaforge/etc/conda
  conda av metadata url : None
           channel URLs : https://conda.anaconda.org/conda-forge/linux-aarch64
                          https://conda.anaconda.org/conda-forge/noarch
          package cache : /home/pi/mambaforge/pkgs
                          /home/pi/.conda/pkgs
       envs directories : /home/pi/mambaforge/envs
                          /home/pi/.conda/envs
               platform : linux-aarch64
             user-agent : conda/4.11.0 requests/2.27.1 CPython/3.9.10 Linux/5.10.103-v8+ debian/11 glibc/2.31
                UID:GID : 1000:1000
             netrc file : None
           offline mode : False
hmaarrfk commented 2 years ago

@Tobias-Fischer

hmaarrfk commented 2 years ago

I'm not even sure that cv.samples.findFile("jurassic_park.png") works. It doesn't on linux. We don't ship the examples.

johnholman commented 2 years ago

It does if you put the image file in the same directory as the script though. For example it works on windows and on the pi (linux-aarch64) if you install opencv-python with pip rather than the conda-forge package.

johnholman commented 2 years ago

But apologise for the unnecessary findFile() etc! Simplified version below produces the same error:

import cv2 as cv img = cv.imread("jurassic_park.png") print(f'image size {img.shape}') cv.imshow("Display window", img) k = cv.waitKey(0)

hmaarrfk commented 2 years ago

I'm sorry to ask. Can you provide the correctly named image. This is just to make it easier for others to help you

hmaarrfk commented 2 years ago

Do you have the equivalent of these packages installed

https://github.com/conda-forge/opencv-feedstock/blob/main/recipe/yum_requirements.txt

johnholman commented 2 years ago

On the image - don't know what copyright situation is for the jurassic one but any image will do - I'll look for something and attach in a moment.

On the mesa-libGL requirement - if that is a conda package I don't think I have it installed. I just tried running "mamba install mesa-libgl" and it said nothing provides it. Can you advise on the right incantation - I can see lots of different related packages with "mamba search mesa-libgl"

johnholman commented 2 years ago

Revised example with image attached:

import cv2 as cv img = cv.imread("bosch_shredder.jpg") print(f'image size {img.shape}') cv.imshow("Display window", img) k = cv.waitKey(0) bosch_shredder

hmaarrfk commented 2 years ago

It should be a package you install with apt or yum.

It provides OpenGL by the operating system

johnholman commented 2 years ago

apt list mesa --installed shows

libegl-mesa0/stable,now 20.3.5-1+rpt3+rpi1 arm64 [installed,automatic] libgl1-mesa-dri/stable,now 20.3.5-1+rpt3+rpi1 arm64 [installed] libglapi-mesa/stable,now 20.3.5-1+rpt3+rpi1 arm64 [installed,automatic] libgles2-mesa/stable,now 20.3.5-1+rpt3+rpi1 arm64 [installed] libglx-mesa0/stable,now 20.3.5-1+rpt3+rpi1 arm64 [installed,automatic] mesa-va-drivers/stable,now 20.3.5-1+rpt3+rpi1 arm64 [installed,automatic] mesa-vdpau-drivers/stable,now 20.3.5-1+rpt3+rpi1 arm64 [installed,automatic]

Does that look sufficient? (Maybe this is is a raspberry pi specific thing?)

johnholman commented 2 years ago

I think qt5 is working on this platform. After also installing pyqt a simple qt application works:

from PyQt5.QtWidgets import QApplication, QWidget import sys app = QApplication(sys.argv) window = QWidget() window.show() app.exec()

I can also use imshow() from matplotlib using the qt backend:

import cv2 as cv import matplotlib.pyplot as plt import matplotlib as mpl

img = cv.imread("bosch_shredder.jpg") img = cv.cvtColor(img, cv.COLOR_BGR2RGB) mpl.use('QtAgg') plt.imshow(img) plt.show()

but calling imshow() from opencv still fails.

NOTE (added to first comment as well)

Even simpler test which doesn't require a test image:

import cv2 cv2.waitKey(0)

which produces similar error:

cv2.error: OpenCV(4.5.5) /home/conda/feedstock_root/build_artifacts/libopencv_1647515468288/work/modules/highgui/src/window.cpp:1334: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvWaitKey'

hajapy commented 2 years ago

Looks like WITH_QT is being set to 0 on these builds: https://dev.azure.com/conda-forge/feedstock-builds/_build/results?buildId=476367&view=logs&j=696704cc-6fef-57a3-ea36-f27779b8cd5e&t=ed2e6513-0a06-519f-13f9-1e5619642f2a&l=2318

Could be due to target_platform "linux-aarch64" failing this check https://github.com/conda-forge/opencv-feedstock/blob/main/recipe/build.sh#L26 and getting disabled.

hmaarrfk commented 2 years ago

Try installing in an hour or two.

johnholman commented 2 years ago

Many thanks - this works now

hmaarrfk commented 2 years ago

Thank you for helping debug so much!

Tobias-Fischer commented 2 years ago

Thanks both - my bad for missing to change the build.sh as well!