Python OpenCV 包与 Linux 不兼容?

标签 python opencv compatibility

我在我的 Windows 上测试了一些代码,它们运行得很好。当在我的 VPS (Debian) 上导出它时,我遇到了一些错误。这是否意味着它根本不可能在 Linux 上运行(我对此无能为力?)?

这是我在包装页面上找到的内容:

MacOS and Linux wheels have currently some limitations: 
- video related functionality is not supported (not compiled with FFmpeg)
- for example ``cv2.imshow()`` will not work (not compiled with GTK+ 2.x or Carbon support)

这是输出错误:

root@vps324173:~/Test# python main.py
 * Running on http://myserverip:5000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 296-193-487
myclientip - - [05/May/2017 04:33:52] "GET / HTTP/1.1" 200 -
a
OpenCV Error: Unknown error code -10 (Raw image encoder error: Empty JPEG image (DNL not supported)) in throwOnEror, file /io/opencv/modules/imgcodecs/src/grfmt_base.cpp, line 139
OpenCV Error: Unknown error code -10 (Raw image encoder error: Empty JPEG image (DNL not supported)) in throwOnEror, file /io/opencv/modules/imgcodecs/src/grfmt_base.cpp, line 139
Debugging middleware caught exception in streamed response at a point where response headers were already sent.
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/wsgi.py", line 704, in __next__
    return self._next()
  File "/usr/local/lib/python2.7/dist-packages/werkzeug/wrappers.py", line 81, in _iter_encoded
    for item in iterable:
  File "/root/Test/main.py", line 14, in gen
    frame = camera.get_frame()
  File "/root/Test/camera.py", line 42, in get_frame
    ret, jpeg = cv2.imencode('.jpg', image)
error: /io/opencv/modules/imgcodecs/src/grfmt_base.cpp:139: error: (-10) Raw image encoder error: Empty JPEG image (DNL not supported) in function throwOnEror
myclientip - - [05/May/2017 04:33:52] "GET /video_feed HTTP/1.1" 200 -

感谢您的帮助!

最佳答案

你可能谈到了 pypi 中的 opencv-python。这是一个非常具有误导性的项目(经常在 pypi、成熟的..中找到),可能对于一些 opencv 安装困​​难的纯操作系统有用。不要在 Debian 风格的 Linux 上使用它。为了进一步澄清:

  • python-opencv 是 Debian 软件包(推荐,包含视频支持)
  • opencv-python 是外部项目(不推荐,集成的 opencv 缺乏视频支持)

所以对于 Debian(,..),我们有这些可能性:

从 Debian 软件包安装

sudo aptitude install libopencv-dev python-opencv
  # /usr/lib/python2.7/dist-packages/cv2.x86_64-linux-gnu.so
sudo aptitude purge libopencv-dev python-opencv  # uninstall

从源安装(github.com/opencv/opencv):

默认支持视频(有关详细信息,请参阅 cmake 的WITH_FFMPEG 标志)

sudo aptitude install build-essential cmake
sudo aptitude install python-dev python-numpy
sudo aptitude install libavdevice-dev libavformat-dev libavfilter-dev libavcodec-dev libswscale-dev libavutil-dev 
sudo aptitude install libgtk2.0-common libgtk2.0-bin libgtk2.0-dev libdc1394-22-dev libv4l-dev libgstreamer-plugins-base1.0-dev
sudo pip install cmake
mkdir build/
cd build/
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
  # check output if FFMPEG status is YES
make
sudo make install --or-- sudo checkinstall --pkgname opencv
  # /usr/local/lib/python2.7/dist-packages/cv2.so
sudo make uninstall --or-- sudo dpkg -r opencv  # uninstall

opencv-python 项目(无需使用它!):opencv WITHOUT VIDEO 支持

sudo pip install opencv-python
  # /usr/local/lib/python2.7/dist-packages/cv2/cv2.so
sudo pip uninstall opencv-python  # uninstall

编解码器语法:

try:
    codec = cv2.VideoWriter_fourcc(*'MJPG')   # newer syntax
except AttributeError:
    codec = cv2.cv.CV_FOURCC(*'MJPG')   # older syntax

关于Python OpenCV 包与 Linux 不兼容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43795663/

相关文章:

Python 使用 urllib 登录 Google

osgi - 如何定义最低 GRE 要求(1.5 _ 或更高 _)?

internet-explorer - 如何将IE11文档模式设置为默认边缘?

c - 如何测试 POSIX 兼容性?

Python 对列表项的唯一列表进行排序

python - 对 django 中列表列表的元素进行排名和计数

python - 从 WordNet 同义词集中获取单词

opencv - 如何用opencv模拟摇晃的凸轮?

java - 在 JavaCV 中将标量转换为 Mat

image - 如何使用opencv比较HSV色彩空间中的两个图像?