使用opencv读取图像

时间:2018-05-18 12:30:43

标签: python opencv

我正在尝试运行眼状态检测的演示项目,我收到以下错误。

    python -m demo --process image --path /home/samuel/Pictures/download.jpeg --json_path /home/samuel/EyeStateDetection/models/model.json --weights /home/samuel/EyeStateDetection/models/model.h5
/home/samuel/anaconda3/lib/python3.6/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters
Using TensorFlow backend.
(183, 275, 3)
OpenCV Error: Unspecified error (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 cvShowImage, file /tmp/build/80754af9/opencv_1512687413662/work/modules/highgui/src/window.cpp, line 611
Traceback (most recent call last):
  File "/home/samuel/anaconda3/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/samuel/anaconda3/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/samuel/EyeStateDetection/demo/__main__.py", line 19, in <module>
    main()
  File "/home/samuel/EyeStateDetection/demo/__main__.py", line 15, in main
    image_demo(json_path,weights,image_path)
  File "/home/samuel/EyeStateDetection/demo/__init__.py", line 372, in image_demo
    cv2.imshow("Image",img)
cv2.error: /tmp/build/80754af9/opencv_1512687413662/work/modules/highgui/src/window.cpp:611: 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

我检查了我的cv2版本,它是3.3.1。我不知道为什么会收到此错误。 导致此错误的代码是

def image_demo(json_path,weights_path,image_path):
     img = cv2.imread(image_path)
     cv2.imshow("Image",img)

1 个答案:

答案 0 :(得分:0)

错误发生在cv2.imshow("Image",img)

您没有安装GTK。使用imshow()时,GTK负责显示图像界面。如果您正在运行Ubuntu,请使用

进行安装
sudo apt-get install libgtk-3-dev

有关OpenCV的完整安装说明,请参阅https://www.pyimagesearch.com/2016/10/24/ubuntu-16-04-how-to-install-opencv/

此外,如果您要使用imshow(),还需要使用cv2.waitKey()

相关问题