Python 2.7 读取网络摄像机时出现Ubuntu OpenCV错误
我可以在Windows中运行相同的程序。我可以在Ubuntu 16.04中使用lsusb看到我的相机,64位。该摄像机为OSVR红外摄像机 我的节目是Python 2.7 读取网络摄像机时出现Ubuntu OpenCV错误,python-2.7,opencv,ubuntu,webcam,Python 2.7,Opencv,Ubuntu,Webcam,我可以在Windows中运行相同的程序。我可以在Ubuntu 16.04中使用lsusb看到我的相机,64位。该摄像机为OSVR红外摄像机 我的节目是 import numpy as np import cv2 camera = cv2.VideoCapture(0) while(True): # Capture frame-by-frame ret, frame = camera.read() cv2.cvtColor(frame, cv2.COLOR_BGR2GRA
import numpy as np
import cv2
camera = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = camera.read()
cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('camera', frame)
# k = cv2.waitKey(30)
# When everything done, release the capture
camera.release()
cv2.destroyAllWindows()
结果是:
cwu@ubuntu:~/project/osvrCamera$ python test.py
select timeout
select timeout
OpenCV Error: Assertion failed (!buf.empty() && buf.isContinuous()) in imdecode_, file /tmp/binarydeb/ros-kinetic-opencv3-3.1.0/modules/imgcodecs/src/loadsave.cpp, line 490
Traceback (most recent call last):
File "test.py", line 8, in <module>
ret, frame = camera.read()
cv2.error: /tmp/binarydeb/ros-kinetic-opencv3-3.1.0/modules/imgcodecs/src/loadsave.cpp:490: error: (-215) !buf.empty() && buf.isContinuous() in function imdecode_
cwu@ubuntu:~/project/osvrCamera$python test.py
选择超时
选择超时
OpenCV错误:imdecode铹文件/tmp/binarydeb/ros-kinetic-opencv3-3.1.0/modules/imgcodecs/src/loadsave.cpp第490行中的断言失败(!buf.empty()&&buf.isContinuous())
回溯(最近一次呼叫最后一次):
文件“test.py”,第8行,在
ret,frame=camera.read()
cv2.error:/tmp/binarydeb/ros-kinetic-opencv3-3.1.0/modules/imgcodecs/src/loadsave.cpp:490:error:(-215)!函数imdecode中的buf.empty()和&buf.isContinuous()_
首先检查框架是否为空()
(当您尝试转换/显示它时,可能cam/框架未完全初始化:
import numpy as np
import cv2
camera = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = camera.read()
if not frame.empty():
cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('camera', frame)
# k = cv2.waitKey(30)
# When everything done, release the capture
camera.release()
cv2.destroyAllWindows()