Python OpenCV软件包与Linux不兼容



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

默认情况下的视频支持(有关详细信息,请参见with_ffmpeg for for cmake(

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 没有视频支持

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

最新更新