Python OpenCV包与Linux不兼容?

问题描述 投票:2回答:1

我在我的窗户上测试了一些完美工作的代码。在我的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 -

感谢帮助 !

python opencv compatibility cv2
1个回答
1
投票

你可能会说pypi中的opencv-python。这是一个非常误导性的项目(通常在pypi中找到,成熟,...),可能对某些具有困难的opencv安装的纯OS很有用。不要在Debian风格的Linux上使用它。更多地澄清一下:

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

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

install from Debian packages

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

install from sources (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没有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
© www.soinside.com 2019 - 2024. All rights reserved.