[Environment configuration] opencv cannot show

question

cv2.imshowAn error is reported when displaying the image, and the image cannot be displayed

  0%|                                                                                                                                                                          | 0/1 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "/home/xxx/workspace/inference.py", line 380, in <module>
    cv2.imshow('result', img)
cv2.error: OpenCV(4.8.0) /io/opencv/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'

It seems that pip3 install opencv-python-headlessthe version is inconsistent after the previous installation.

solution

pip3 uninstall opencv-python
pip3 install opencv-python-contrib
pip3 install opencv-python

References

Solve the problem: If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then...'cvShowImage'

Guess you like

Origin blog.csdn.net/zhoujinwang/article/details/131579348