Rebuild the library with windows gtk 2 x or cocoa support

System Information

OpenCV version: 4.7.0
Operating System / Platform: Ubuntu 18.04
Compiler & compiler version: GCC 7.5.0
pkg-config gtk+-2.0 —modversion (2.24.32)
pkg-config gtk+-3.0 —modversion (3.22.30)
pkg-config gthread-2.0 —modversion (2.56.4)

Detailed description

terminate called after throwing an instance of ‘cv::Exception’
what(): OpenCV(4.7.0) /usr/src/opencv-4.7.0/modules/highgui/src/window.cpp:1272: 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’

Steps to reproduce

in opencv-4.7.0 dir:
sudo mkdir build
cd build
sudo cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/usr/src/opencv-4.7.0/opencv_contrib-4.7.0/modules -D WITH_CUDA=ON -D ENABLE_FAST_MATH=1 -D CUDA_FAST_MATH=1 -D WITH_CUBLAS=1 -D WITH_CUDNN=1 -DWITH_GTK=ON ..
sudo make -j32
sudo make install

I have turned on the support for GPU and DNN modules in my compilation options, and I can compile successfully, but when I use cv::imshow() in the code, it will throw a display error, just like the error error message I provided , could you please help me to see how I can fix this problem? thank you!

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)

Recommended Posts

I installed devian10 on tinker-edge-r.

The following error occurred as soon as cv2.imshow() was performed with the test code.

And I try to apt-get install libgtk2.0-dev and pkg-config.
How can I resolve the error?

Quote

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'


Edited by Goolge

Share this post


Link to post
Share on other sites

hello @Goolge, 

what is your test code? have you done what the notice suggested?

(If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function 'cvShowImage')

Share this post


Link to post
Share on other sites

just tested the cv2.imshow() function on my side and no errors shown. if the debian 10 os you’re using is the official release from our website, python/ opencv pakages are built in the image; if you’re using a third party debian 10 os, maybe follow this tutorial to get all the necessary libs/ pkgs installed: https://linuxize.com/post/how-to-install-opencv-on-debian-10/

Share this post


Link to post
Share on other sites

On 9/2/2022 at 5:07 PM, tooz said:

just tested the cv2.imshow() function on my side and no errors shown. if the debian 10 os you’re using is the official release from our website, python/ opencv pakages are built in the image; if you’re using a third party debian 10 os, maybe follow this tutorial to get all the necessary libs/ pkgs installed: https://linuxize.com/post/how-to-install-opencv-on-debian-10/

Thank you very much.
I almost gave up.
I’ll give it a try.

I have one more question.
Two webcams were connected in the tinker edge. ‘cv2.open’ works well for two webcams, but only one webcam can be read. How do I ‘cv2.read’ two webcams at the same time?

Share this post


Link to post
Share on other sites

Hi,

Usually, before you use `cv2.open`, should have a define codes to let cv2 know use which camera.

so should such as:

import cv2
cam0 = cv2.VideoCapture(0)
cam1 = cv2.VideoCapture(1)
ret0, frame0 = cam0.read()

and node ID is based on your camera node in system.

Share this post


Link to post
Share on other sites

On 9/2/2022 at 9:07 AM, tooz said:

just tested the cv2.imshow() function on my side and no errors shown. if the debian 10 os you’re using is the official release from our website, python/ opencv pakages are built in the image; if you’re using a third party debian 10 os, maybe follow this tutorial to get all the necessary libs/ pkgs installed: https://linuxize.com/post/how-to-install-opencv-on-debian-10/

i have downloaded the debian 10 official realease from tinker board asus website and then followed your suggested tutorial to install opencv but i am still getting the error:

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'


Edited by marco@bigsis.tech

Share this post


Link to post
Share on other sites

hello @marco@bigsis.tech

which version of opencv were you building? were you building it on tinker board 2s?

Share this post


Link to post
Share on other sites

Hi,

thank you for your reply. No, I am building it on the Tinker Edge R, and the downloaded version of opencv after following that  tutorial is 4.6.0.

I also tried to execute the RKNN toolkit which gives opencv 4.4.0 and still got that error message.


Edited by marco@bigsis.tech

Share this post


Link to post
Share on other sites

19 minutes ago, tooz said:

hello @marco@bigsis.tech

which version of opencv were you building? were you building it on tinker board 2s?

Hi,

thank you for your reply. No, I am building it on the Tinker Edge R, and the downloaded version of opencv after following that  tutorial is 4.6.0.

I also tried to execute the RKNN toolkit which gives opencv 4.4.0 and still got that error me


Edited by marco@bigsis.tech

Share this post


Link to post
Share on other sites

hello @marco@bigsis.tech, 

i was testing tinker board 2s and did manage to compile opencv:

sudo apt-get update
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev


git clone https://github.com/opencv/opencv.git
cd opencv/
git checkout 4.1
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D INSTALL_C_EXAMPLES=OFF \
-D PYTHON_EXECUTABLE=$(which python3) \
-D BUILD_opencv_python2=OFF \
-D PYTHON3_EXECUTABLE=$(which python3) \
-D WITH_GSTREAMER=ON ..
make && sudo make install

will check on tinker edge r and let you know 

Share this post


Link to post
Share on other sites

2 minutes ago, tooz said:

hello @marco@bigsis.tech, 

i was testing tinker board 2s and did manage to compile opencv:

sudo apt-get update
sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev


git clone https://github.com/opencv/opencv.git
cd opencv/
git checkout 4.1
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D INSTALL_C_EXAMPLES=OFF \
-D PYTHON_EXECUTABLE=$(which python3) \
-D BUILD_opencv_python2=OFF \
-D PYTHON3_EXECUTABLE=$(which python3) \
-D WITH_GSTREAMER=ON ..
make && sudo make install

will check on tinker edge r and let you know 

thank you for your response, I will try uninstall opencv and recompile it with your modification and let you know as well

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

16 hours ago, marco@bigsis.tech said:

Hi,

thank you for your reply. No, I am building it on the Tinker Edge R, and the downloaded version of opencv after following that  tutorial is 4.6.0.

I also tried to execute the RKNN toolkit which gives opencv 4.4.0 and still got that error message.

hello @marco@bigsis.tech, 

so the version of opencv-python was upgraded, if you’ve encountered import cv2.imshow() error, please remove the build-in opencv-python:

python3 -m pip uninstall opencv-python

then re-install:

python3 -m pip install opencv-python --user 

Share this post


Link to post
Share on other sites

1 hour ago, tooz said:

hello @marco@bigsis.tech, 

so the version of opencv-python was upgraded, if you’ve encountered import cv2.imshow() error, please remove the build-in opencv-python:

python3 -m pip uninstall opencv-python

then re-install:

python3 -m pip install opencv-python --user 

Hi,

thank you again for your quick response.

at the end I was able to solve the error by re-compiling opencv  following the same tutorial  BUT  installing  libgtk2.0-dev  instead of libgtk-3-dev.

I will try your suggestion as well.

However I am currently facing another problem..

I am trying to capture videos from 4 usb cameras.  I am able to preview only 3 cameras together, but if I try with 4 I gets the following error:

(-215:Assertion failed) size.width>0 && size.height>0 in function ‘cv::imshow

Any suggestion please?

WhatsApp Image 2022-11-24 at 10.22.13.jpeg

Share this post


Link to post
Share on other sites

hello @marco@bigsis.tech, 

this is the imshow function error, perhaps you want to check and adjust the import frame

Share this post


Link to post
Share on other sites

6 hours ago, tooz said:

hello @marco@bigsis.tech, 

this is the imshow function error, perhaps you want to check and adjust the import frame

Hello,

Do you mean the frame size?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Sign in

Already have an account? Sign in here.

Sign In Now


0

1

Решил поюзать диспечер пакетов vcpkg и установил в нем opencv (vcpkg install grpc). При этом консольные проекты, выполняющие просто обработку изображений нормально собираются и запускаются.

При попытке запустить приложение с «окошком» (визуальное отображение рисунка imshow) возникает ошибка:

OpenCV(4.3.0) Error: 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 cvWaitKey, file /home/cvprog/vcpkg/buildtrees/opencv4/src/4.3.0-0c6047baf6.clean/modules/highgui/src/window.cpp, line 717

Предполажил, что в vcpkg нужно поставить gtk:

./vcpkg update
./vcpkg install gtk
...
CMake Error at scripts/cmake/vcpkg_execute_required_process.cmake:85 (message):
    Command failed: autoreconf -v --install
    Working Directory: /home/cvprog/vcpkg/buildtrees/libepoxy/src/1.5.4-337c486045.clean
    Error code: 1
...
Error: Building package libepoxy:x64-linux failed with: BUILD_FAILED
$ cat /home/cvprog/vcpkg/buildtrees/libepoxy/autoreconf-x64-linux-err.log
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal -I m4
configure.ac:36: error: must install xorg-macros 1.8 or later before running autoconf/autogen.
  Hint: either install from source, git://anongit.freedesktop.org/xorg/util/macros or,
  depending on you distribution, try package 'xutils-dev' or 'xorg-x11-util-macros'
configure.ac:36: the top level
autom4te: /usr/bin/m4 failed with exit status: 1
aclocal: error: echo failed with exit status: 1
autoreconf: aclocal failed with exit status: 1
$ ./vcpkg install xorg-macros
Computing installation plan...
Error: Cannot find definition for package `xorg-macros`.

Подскажите что можно сделать?

Issue Overview

Users are experiencing issues when attempting to run OpenCV applications on the Nvidia Jetson Orin Nano Dev board using a PyTorch Docker image (nvcr.io/nvidia/pytorch:24.05-py3-igpu). The specific error message encountered is:

cv2.error: OpenCV(4.7.0) /opencv-4.7.0/modules/highgui/src/window.cpp:1338: error: (-2:Unspecified error) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Cocoa support.

This issue arises when executing a sample OpenCV program (test_cam.py) that attempts to display video from two camera sources using the GStreamer backend. The problem occurs consistently when the cv2.waitKey() function is called, indicating that the necessary GUI support for OpenCV is missing.

The user has installed opencv-python==4.8.0.74 but continues to face errors related to GUI functionality, suggesting that the library may not have been built with the required support for GTK+.

Possible Causes

  • Missing Dependencies: The absence of libgtk2.0-dev and pkg-config can prevent OpenCV from utilizing GUI features.

  • Incorrect OpenCV Build: The installed version of OpenCV may not have been compiled with support for GUI frameworks like GTK+, leading to the observed errors.

  • Docker Environment Limitations: Running applications inside a Docker container can sometimes restrict access to graphical interfaces unless configured correctly.

  • Version Mismatch: The user is running OpenCV version 4.7.0, while they mentioned installing opencv-python==4.8.0.74, which may indicate a version conflict or improper installation.

Troubleshooting Steps, Solutions & Fixes

  1. Install Required Packages:
    To ensure that all necessary dependencies are installed, run the following command in your terminal:

    sudo apt-get install libgtk2.0-dev pkg-config
    
  2. Rebuild OpenCV:
    If the above command does not resolve the issue, you may need to rebuild OpenCV with the correct flags for GUI support:

    • First, remove existing installations of OpenCV:
      pip uninstall opencv-python opencv-python-headless
      
    • Clone the OpenCV repository and build it:
      git clone https://github.com/opencv/opencv.git
      cd opencv
      mkdir build
      cd build
      cmake -D WITH_GTK=ON ..
      make -j$(nproc)
      sudo make install
      
  3. Check Docker Configuration:
    Ensure that your Docker container has access to the X11 server for GUI applications:

    • Run your Docker container with the following flags:
      docker run -it --rm --runtime=nvidia --gpus all \
        -e DISPLAY=$DISPLAY \
        -v /tmp/.X11-unix:/tmp/.X11-unix \
        nvcr.io/nvidia/pytorch:24.05-py3-igpu
      
  4. Test with a Simple Script:
    After installing dependencies and rebuilding OpenCV, test with a minimal script to verify that cv2.imshow() works correctly:

    import cv2
    import numpy as np
    
    img = np.zeros((512, 512, 3), np.uint8)
    cv2.imshow('Test Image', img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    
  5. Verify Installation:
    Check if OpenCV was built with GTK+ support using:

    import cv2
    print(cv2.getBuildInformation())
    

    Look for «GUI» in the output; it should indicate GTK+ support.

  6. Reinstalling Specific Versions:
    If issues persist, consider installing a specific version of OpenCV known to work well in your environment:

    pip install opencv-python==4.5.3.20210927  # Example version; adjust as needed.
    
  7. Consult Documentation:
    Refer to the official OpenCV documentation and Nvidia forums for additional guidance on compatibility and installation instructions specific to Jetson devices.

By following these steps, users should be able to resolve the issues related to GUI functionality in their OpenCV applications on the Nvidia Jetson Orin Nano Dev board. If problems persist after these troubleshooting steps, further investigation into specific environment configurations may be necessary.

OpenCV “The function is not implemented. Rebuild the library with Windows”

I see problem unsolvable.I get this error when I try to import numpy

import cv2
import numpy as np

img=cv2.imread('image.jpg',1)
cv2.imshow('image', img)
cv2.waitkey()
cv2.destroyAllWwindows()

when I run attribute imread is not working

cv2.error: OpenCV(3.4.1) C:projectsopencv-pythonopencvmoduleshighguisrcwindow.cpp:636: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon 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

Please help, Python version 3.6

OpenCV version :3.4.1

matplotlib version : 2.2.2

Advertisement

Answer

I had the same issue too. Despite they were installed before, I’ve installed them again via:

pip install opencv-python 
pip install opencv-contrib-python 

and problem solved.

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Как найти путь файла в windows 10
  • Тема для компьютера windows 10 космос
  • Windows event id 4656
  • Days gone запуск на windows 7
  • Автозагрузка windows 10 как настроить