LoginSignup
11
9

More than 3 years have passed since last update.

OpenCVのimshow()の注意点

Last updated at Posted at 2020-07-13

OpenCVのimshowでズラっと何か表示される

授業でopenCVを触ることになったので、まずはinstall。ちなみにmac勢、Python 3.7.4

pip install opencv-python

そして、画像を表示するだけのtest.pyを作成。

test.py

import cv2
img = cv2.imread('mona.jpg')
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

実行すると画像は表示されたものの、

objc[62826]: Class RunLoopModeTracker is implemented in both /Users/ユーザー名/.pyenv/versions/anaconda3-2019.10/lib/python3.7/site-packages/cv2/.dylibs/QtCore (0x1139e97f0) and /Users/ユーザー名/.pyenv/versions/anaconda3-2019.10/lib/libQt5Core.5.9.7.dylib (0x128195a80). One of the two will be used. Which one is undefined.
QObject::moveToThread: Current thread (0x7fc0f7435300) is not the object's thread (0x7fc0f9f02cc0).
Cannot move to target thread (0x7fc0f7435300)

You might be loading two sets of Qt binaries into the same process. Check that all plugins are compiled against the right Qt binaries. Export DYLD_PRINT_LIBRARIES=1 and check that only one set of binaries are being loaded.
QObject::moveToThread: Current thread (0x7fc0f7435300) is not the object's thread (0x7fc0f9f02cc0).
Cannot move to target thread (0x7fc0f7435300)

(後略)

後略の部分には「You might be-」と似たような文書がズラッと続きます。
画像が表示されているとはいえ、流石に気になる。

少し調べてみるとこちらで似たような事例の方を発見。

「複数のパッケージがGUIの機能を持ってるとマズイから、GUIの機能の無いverをインストールすればいい」
とのことでGUI機能の無いopencv-python-headlessをインストールすれば良いらしい。

pip install opencv-python-headless

謎の数百行は無事消滅。一安心。ちなみに、画像を選択した状態でキーボード入力をすると終了します。

しかし、公式と思われるサイト曰く、適切な物を一つだけインストールしないといけないらしいので、opencv-pythonをuninstall。

pip uninstall opencv-python

すると、必要なheadlessも纏めてuninstallされたっぽいので、再びinstall。

pip install opencv-python-headless

以上、終了。

11
9
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
11
9