我在我的窗户上测试了一些完美工作的代码。在我的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安装的纯OS很有用。不要在Debian风格的Linux上使用它。更多地澄清一下:
所以对于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
默认情况下支持视频(有关详细信息,请参阅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
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