本文介绍了Python OpenCV:Python 2.7与Python 3.5之间的VideoCapture差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过ssh连接到远程系统,并尝试使用Python中的OpenCV VideoCapture读取帧.使用Python 2.7时,相同的代码成功;使用Python 3.5时,相同的代码失败:
I'm connected to remote system through ssh, and trying to read frames using OpenCV VideoCapture in Python. The same code succeeds when using Python 2.7 and fails when using Python 3.5:
import cv2
cap = cv2.VideoCapture(0)
Python2.7:
Python2.7:
print cap.isOpened() # prints True, further read() calls also return True
Python3.5:
Python3.5:
print (cap.isOpened()) # prints False, and so are cap.open(), and of course cap.read().
什么可能导致这种行为?
What could cause such behavior?
谢谢!
推荐答案
我遇到了完全相同的问题. OpenCV是从源代码安装的.Python 2和3环境之间的区别在于,对于Python 3,通过pip3 另外安装了opencv-python. A
I had exactly the same problem. OpenCV was installed from the sources.The difference between Python 2 and 3 environment was, that for Python 3 opencv-python was additionally installed via pip3. A
pip3 uninstall opencv-python
解决了我的情况.
这篇关于Python OpenCV:Python 2.7与Python 3.5之间的VideoCapture差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!