本文整理匯總了Python中cv2.VideoCapture.open方法的典型用法代碼示例。如果您正苦於以下問題:Python VideoCapture.open方法的具體用法?Python VideoCapture.open怎麽用?Python VideoCapture.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cv2.VideoCapture
的用法示例。
在下文中一共展示了VideoCapture.open方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Camera
# 需要導入模塊: from cv2 import VideoCapture [as 別名]
# 或者: from cv2.VideoCapture import open [as 別名]
class Camera(object):
''' Communicate with the camera.
Class governing the communication with the camera.
Parameters
-----------
camera : int
the index of the camera, best taken from func lookForCameras,
from eyetracker.camera.capture
dic : dic{propID value}
to check corresponding propIDs check
opencv documentation under the term VideoCapture.
They will be set in the moment of object creation.
Defines
--------
self.camera : index of the camera
self.cap : capturing object
self.frame : returns a frame from camera
self.close : closes cap
self.reOpen : reopens cap
'''
def __init__(self, camera, dic=None):
self.camera = int(camera)
self.cap = VideoCapture(self.camera)
if dic:
for propID, value in dic.iteritems():
self.cap.set(propID, value)
first_frame = self.frame()
def frame(self):
''' Read frame from camera.
Returns
--------
frame : np.array
frame from camera
'''
if self.cap.isOpened:
return self.cap.read()[1]
else:
print 'Cap is not opened.'
return None
def set(self, **kwargs):
''' Set camera parameters.
Parameters
-----------
kwargs : {propID : value}
'''
for propID, value in kwargs.iteritems():
self.cap.set(propID, value)
def close(self):
''' Closes cap, you can reopen it with self.reOpen.
'''
self.cap.release()
def reOpen(self, cameraIndex):
''' Reopens cap.
'''
self.cap.open(self.camera)
first_frame = self.frame()