无法让opencv在我的mac

时间:2018-01-06 22:28:44

标签: python-3.x opencv matplotlib gtk virtualenv

我正在尝试使用可在此处找到的酷库进行人体姿势估计:

https://github.com/DeNA/Chainer_Realtime_Multi-Person_Pose_Estimation

我使用tkagg后端处理静止图像,通过以下行设置:

import matplotlib
matplotlib.use('tkagg')
import matplotlib.pyplot as plt

不幸的是,要进行实时网络摄像头跟踪,似乎tkagg无法正常工作。当我运行代码进行实时网络摄像头跟踪时,我收到以下错误:

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 /Users/travis/build/skvark/opencv-python/opencv/modules/highgui/src/window.cpp, line 583

这似乎告诉我使用GTK后端,这是有意义的,因为这是原始的回购说使用。问题是我将matplotlib.use行更改为GTK,如下所示:

import matplotlib
matplotlib.use('GTK')
import matplotlib.pyplot as plt

这会产生以下跟踪错误:

追踪(最近一次通话):   文件“/Users/mark/Downloads/myenv3.5/lib/python3.5/site-packages/matplotlib/backends/backend_gtk.py”,第14行,in     import gobject ImportError:没有名为'gobject'的模块

在处理上述异常期间,发生了另一个异常:

Traceback (most recent call last):
File "camera_pose_demo.py", line 4, in <module>
    from pose_detector import PoseDetector, draw_person_pose
File "/Users/mark/Downloads/Chainer_Realtime_Multi-Person_Pose_Estimation-master/pose_detector.py", line 8, in <module>
    import matplotlib.pyplot as plt
File "/Users/mark/Downloads/myenv3.5/lib/python3.5/site-packages/matplotlib/pyplot.py", line 116, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/Users/mark/Downloads/myenv3.5/lib/python3.5/site-packages/matplotlib/backends/__init__.py", line 60, in pylab_setup
    [backend_name], 0)
File "/Users/mark/Downloads/myenv3.5/lib/python3.5/site-packages/matplotlib/backends/backend_gtk.py", line 18, in <module>
    raise ImportError("Gtk* backend requires pygtk to be installed.")
ImportError: Gtk* backend requires pygtk to be installed.

这显然是说我的程序无法找到GTK后端。我已经通过brew安装了它,但我也读过其他人也有这个问题 - 只是没有一个明确的答案。似乎我需要在我的机器上找到GTK并明确地告诉我的python程序/ virtualenv在哪里,虽然我不知道如何做到这一点。

1 个答案:

答案 0 :(得分:0)

你需要安装PyGTK(GTK的python包装器),而这需要pygobject(GObject的python包装器)。

PyGTK似乎相当陈旧(2011年),我不确定它是否适用于Python 3。