本文整理汇总了Python中cv2.VideoCapture.retrieve方法的典型用法代码示例。如果您正苦于以下问题:Python VideoCapture.retrieve方法的具体用法?Python VideoCapture.retrieve怎么用?Python VideoCapture.retrieve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv2.VideoCapture
的用法示例。
在下文中一共展示了VideoCapture.retrieve方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: camera
# 需要导入模块: from cv2 import VideoCapture [as 别名]
# 或者: from cv2.VideoCapture import retrieve [as 别名]
class camera(object):
'''
Object containing camera information
Call-able, retrieve current frame in camera buffer
User accessible attributes:
device system device number
resolution camera resolution
BGRimage image in BGR format
HSVimage image in HSV format
RGBimage image in RGB format
FPS camera speed in FPS
User accessible methods:
close close camera device
'''
def __init__(self, cam_num = -1, resolution = (640, 480)):
'''
create camera object
cam_num device number (integer)
resolution image resolution (tuple width x height)
'''
self.device = cam_num
self.resolution = resolution
self.BGRimage = []
self.HSVimage = []
self.RGBimage = []
self.FPS = [0, 0]
self.__avr = 0
#assign and open device
self.__capture = VideoCapture(cam_num)
self.__capture.set(CV_CAP_PROP_FRAME_WIDTH,resolution[0])
self.__capture.set(CV_CAP_PROP_FRAME_HEIGHT,resolution[1])
self.__capture.open
self.__flag = False
t0 = time()
self.__flag, self.BGRimage = self.__capture.read()
self.FPS[0] = 1/(time()-t0)
self.FPS[1] = self.FPS[0]
self.__avr = self.FPS[0]
print "camera", self.device, "ready @", self.FPS[0], "fps"
return
def __call__(self, frame_delay = 0, fast = False):
'''
retrieve current frame in camera buffer
frame_delay delay the frame decoding (integer)
fast if true don't decode image to RGB format (logic)
'''
#set timer to meassure fps
self.__avr = self.FPS[1]
t0 = time()
#try to retrieve current frame
while not self.__flag:
if frame_delay > 0:
for i in xrange(frame_delay + 1):
self.__capture.grab()
self.__flag, self.BGRimage = self.__capture.retrieve()
del i
else:
self.__flag, self.BGRimage = self.__capture.read()
self.__flag = False
#decode bgr format to hsv
self.HSVimage = cvtColor(self.BGRimage, CV_BGR2HSV)
if fast:
self.FPS[0] = 1/(time()-t0)
self.FPS[1] = (self.FPS[0]+self.__avr)/2
return
#decode bgr format to rgb
self.RGBimage = cvtColor(self.BGRimage, CV_BGR2RGB)
self.FPS[0] = 1/(time()-t0)
self.FPS[1] = (self.FPS[0]+self.__avr)/2
return
def __str__(self):
'''
return camera information;
device number
device resolution
instant speed
average speed
'''
tmp = "camera object @ dev "+str(self.device)+", resolution: "+str(self.resolution)
tmp = tmp +", fps: "+str(self.FPS[0])+", Avr. fps: "+str(self.FPS[1])
return tmp
def __del__(self):
'''
when the object is deleted, it closes the device
'''
self.close()
return
def close(self):
'''
close device, making it available to use
'''
#if the device is open then close it
if self.__capture.isOpened():
self.__capture.release()
print "camera", self.device, "closed"
return