LoginSignup
3
1

More than 1 year has passed since last update.

OpenCVのimshowでエラーが出る時の対処法 [WSL2 / Ubuntu]

Posted at

概要

PythonのOpenCVでimshowを実行したときにエラーが出る場合の対処法です。

環境

  • WSL2
    • Ubuntu 20.04
  • Python 3.8.10
  • pip 23.0.1

エラー内容

cv2.error: OpenCV(4.6.0) /io/opencv/modules/highgui/src/window.cpp:1267: 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'

解決策

エラー文に表示されているパッケージのインストールとOpenCVの再インストールを行います。

1. OpenCVのアンインストール

pip3 uninstall opencv-python

2. libgtk2.0-devpkg-configのインストール

sudo apt update
sudo apt install -y libgtk2.0-dev pkg-config

3. OpenCVの再インストール

pip3 install opencv-python

再インストールが完了すると、このようにimshowが実行できるようになります。
image.png

参考

Btw, sudo apt install libgtk2.0-dev pkg-config and then re-compiling OpenCV fixed this.

GUI apps built with OpenCV from WSL vcpkg don't work #4104

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1