本文整理汇总了Python中VideoCapture.Device.saveSnapshot方法的典型用法代码示例。如果您正苦于以下问题:Python Device.saveSnapshot方法的具体用法?Python Device.saveSnapshot怎么用?Python Device.saveSnapshot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VideoCapture.Device
的用法示例。
在下文中一共展示了Device.saveSnapshot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: saveSnapshot
# 需要导入模块: from VideoCapture import Device [as 别名]
# 或者: from VideoCapture.Device import saveSnapshot [as 别名]
def saveSnapshot(self):
webcam_source = self.webcam_source
if os.path.isdir(webcam_source):
logger.debug('%s webcam choosing random image from "%s"' %
(self, webcam_source))
from random import choice
webcam_source = os.path.join(webcam_source,
choice(os.listdir(webcam_source)))
print webcam_source
if is_file_image(webcam_source):
logger.debug('Webcam %s returning mock image file "%s"' %
(self, webcam_source))
return webcam_source
snapshot_file = self.snapshot_file
if not snapshot_file:
snapshot_file = _get_tmp_filename()
logger.debug('Using temporary file "%s"' % (snapshot_file))
if WIN:
try:
cam = Device(int(self.webcam_source))
cam.saveSnapshot(snapshot_file)
time.sleep(1.0)
cam.saveSnapshot(snapshot_file)
except Exception:
return ''
elif LINUX:
callargs = [self.webcam_source, '-v', 'v4l2src', '!',
'decodebin', '!', 'ffmpegcolorspace', '!', 'pngenc',
'!', 'filesink', 'location="%s"' % (snapshot_file)]
if 0 != subprocess.call(callargs):
return ''
return snapshot_file
示例2: capImage
# 需要导入模块: from VideoCapture import Device [as 别名]
# 或者: from VideoCapture.Device import saveSnapshot [as 别名]
def capImage(self, name, resolution=(1280, 720)):
logger.info("capture picture to %s", name)
cam = Device()
logger.debug("start camera")
cam.setResolution(*resolution)
cam.saveSnapshot(name)
logger.debug("capture picture")
示例3: capture_image
# 需要导入模块: from VideoCapture import Device [as 别名]
# 或者: from VideoCapture.Device import saveSnapshot [as 别名]
def capture_image(self, name, resolution=(1280, 720)):
"""
The object construction and invoking should in same thread, otherwise it will cause blocking.
"""
logger.debug("Capture image to '%s' with resolution '%s'", name, resolution)
from VideoCapture import Device
cam = Device(devnum=self.devnum)
cam.setResolution(*resolution)
try:
cam.saveSnapshot(name)
except AttributeError:
logger.exception("")
logger.debug("Webcam capture image failed, try is again.")
cam.saveSnapshot(name)
示例4: do_cam
# 需要导入模块: from VideoCapture import Device [as 别名]
# 或者: from VideoCapture.Device import saveSnapshot [as 别名]
def do_cam():
L = []
i = 0
cam = Device()
thread.start_new_thread(input_thread, (L,))
while 1:
time.sleep(waitTime)
i = i + 1
istr = str(i)
cam.saveSnapshot("imgs/" + istr + ".png")
print "saved" + istr
if L:
main()
break
示例5: main
# 需要导入模块: from VideoCapture import Device [as 别名]
# 或者: from VideoCapture.Device import saveSnapshot [as 别名]
def main():
cam = Device(devnum=0)
print "press 'ctrl + c' to terminate"
i = 0
quant = interval * .1
starttime = time.time()
while 1:
lasttime = now = int((time.time() - starttime) / interval)
vs = current_datetime_str()
print i,'|',vs
cam.saveSnapshot('photos/ssc%s.jpg' %vs, timestamp=3, boldfont=1)
i += 1
while now == lasttime:
now = int((time.time() - starttime) / interval)
time.sleep(quant)
示例6: main
# 需要导入模块: from VideoCapture import Device [as 别名]
# 或者: from VideoCapture.Device import saveSnapshot [as 别名]
def main(s_time=5):
path1 = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")+'.jpg'
cam = Device()
time.sleep(2)
path2 = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")+'.jpg'
cam.saveSnapshot(path1)
for i in range(10):
time.sleep(s_time)
cam.saveSnapshot(path2)
if calc_similar_by_path(path1,path2)<0.8:
path1 = datetime.now().strftime("%Y_%m_%d_%H_%M_%S")+'.jpg'
tmp = path2
path2 = path1
path1 = tmp
del cam
示例7: Webcam
# 需要导入模块: from VideoCapture import Device [as 别名]
# 或者: from VideoCapture.Device import saveSnapshot [as 别名]
class Webcam():
def __init__(self, webcam_name=None, webcam_id=None, **kargs):
self.device = None
print 'Webcam\t__init__ called with webcam_name=%s and webcam_id=%s' % (webcam_name, webcam_id)
if webcam_name is not None:
self.connect(device_name=webcam_name)
elif webcam_id is not None:
self.connect(device_number=webcam_id)
def options(self, device_name=None, device_number=None):
# I doubt people will have more than 5 webcams plugged in
print 'Webcam\toptions() called'
opts = []
for i in range(2):
try:
print 'Webcam\toptions - attempting to connect to %s' % i
d = Device(devnum=i)
if device_name is not None and device_name == d.getDisplayName():
del self.device
self.device = d
elif device_number is not None and device_number == i:
del self.device
self.device = d
opts.append((i, d.getDisplayName()))
del d
except:
pass
print 'Webcam\toptions() returning %s' % opts
return opts
def connect(self, device_name=None, device_number=None):
if device_name is not None:
self.options(device_name=device_name)
elif device_number is not None:
self.options(device_number=device_number)
else:
self.device = Device()
def disconnect(self):
del self.device
self.device = None
def savePicture(self, path, iterations=15):
for i in range(iterations):
self.device.saveSnapshot(path)
def connected(self):
return (self.device != None)
示例8: camera_capture
# 需要导入模块: from VideoCapture import Device [as 别名]
# 或者: from VideoCapture.Device import saveSnapshot [as 别名]
def camera_capture():
#抓取频率
SLEEP_TIME=3
i=0
cam=Device(devnum=0, showVideoWindow=0)
while i<10:
cam_time=time.strftime('%Y%m%d%H%M%S',time.localtime(time.time()))
cam_name='camera'+cam_time+'.jpg'
cam.saveSnapshot(cam_name,3,1,'bl')
camera_upload(cam_name)
print str(i)+cam_name
os.remove(cam_name)
time.sleep(SLEEP_TIME)
i+=1
示例9: webcamshot
# 需要导入模块: from VideoCapture import Device [as 别名]
# 或者: from VideoCapture.Device import saveSnapshot [as 别名]
def webcamshot(self, filename):
''' Takes a snapshot with the webcam and returns the path to the
saved image (in TMP). None if could not take the snapshot.
'''
if not self.configuration['camshot']:
self.log.info('Skipping webcamshot.')
return None
temp = gettempdir()
self.log.info('Taking webcamshot')
if self.os_name == 'Windows':
filepath = '{}_webcam.jpg'.format(os.path.join(temp, filename))
try:
cam = Device(devnum=0)
if not cam:
cam = Device(devnum=1)
except Exception as ex:
self.log.error('vidcap.Error: %s', ex)
return None
try:
# Here you can modify the picture resolution
# cam.setResolution(768, 576)
cam.getImage()
time.sleep(1)
cam.saveSnapshot(filepath)
except ValueError as ex:
self.log.error(ex)
return None
else:
filepath = '{}_webcam.{}'.format(
os.path.join(temp, filename),
self.configuration['camshot_filetype'])
cmd = self.configuration['camshot'].replace('<filepath>', filepath)
self.runprocess(cmd, useshell=True)
if os.path.isfile(filepath):
if self.configuration['camshot_filetype'] == 'ppm':
full_path_ = os.path.join(temp, filename)
new_path_ = '{}_webcam.jpg'.format(full_path_)
self.runprocess(['/usr/bin/convert', filepath, new_path_])
os.unlink(filepath)
filepath = new_path_
if not os.path.isfile(filepath):
return None
return filepath
示例10: webcamshot
# 需要导入模块: from VideoCapture import Device [as 别名]
# 或者: from VideoCapture.Device import saveSnapshot [as 别名]
def webcamshot(filename):
'''
Takes a snapshot with the webcam and returns the path to the
saved image (in TMP). None if could not take the snapshot.
'''
if not CONFIG['camshot']:
LOG.info('Skipping webcamshot.')
return None
temp = tempfile.gettempdir()
LOG.info('Taking webcamshot')
if OS == 'Windows':
filepath = '{0}{1}{2}_webcam.jpg'.format(temp, SEP, filename)
try:
cam = Device(devnum=0)
if not cam:
cam = Device(devnum=1)
except Exception as ex:
LOG.error('vidcap.Error: %s', ex)
return None
try:
# Here you can modify the picture resolution
#cam.setResolution(768, 576)
cam.getImage()
time.sleep(1)
cam.saveSnapshot(filepath)
except ValueError as ex:
LOG.error(ex)
return None
else:
filepath = '{0}{1}{2}_webcam.{3}'.format(temp, SEP, filename,
CONFIG['camshot_filetype'])
cmd = CONFIG['camshot'].replace('<filepath>', filepath)
runprocess(cmd, useshell=True)
if os.path.isfile(filepath):
if CONFIG['camshot_filetype'] == 'ppm':
new_filepath = '{0}{1}{2}_webcam.jpg'.format(
temp, SEP, filename)
runprocess(['/usr/bin/convert', filepath, new_filepath])
os.unlink(filepath)
filepath = new_filepath
if not os.path.isfile(filepath):
return None
return filepath
示例11: camera
# 需要导入模块: from VideoCapture import Device [as 别名]
# 或者: from VideoCapture.Device import saveSnapshot [as 别名]
def camera():
res = (640,480)
pygame.init()
cam = Device()
cam.setResolution(res[0],res[1])
screen = pygame.display.set_mode((640,480))
pygame.display.set_caption('Webcam')
pygame.font.init()
font = pygame.font.SysFont("Courier",11)
def disp(phrase,loc):
s = font.render(phrase, True, (200,200,200))
sh = font.render(phrase, True, (50,50,50))
screen.blit(sh, (loc[0]+1,loc[1]+1))
screen.blit(s, loc)
brightness = 1.0
contrast = 1.0
shots = 0
while 1:
camshot = ImageEnhance.Brightness(cam.getImage()).enhance(brightness)
camshot = ImageEnhance.Contrast(camshot).enhance(contrast)
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
keyinput = pygame.key.get_pressed()
#if keyinput[K_1]: brightness -= .1
#if keyinput[K_2]: brightness += .1
#if keyinput[K_3]: contrast -= .1
#if keyinput[K_4]: contrast += .1
if keyinput[K_q]: sys.exit()
#if keyinput[K_w]: cam.displayCaptureFilterProperties()
if keyinput[K_s]:
filename = str(time.time()) + ".jpg"
cam.saveSnapshot(filename, quality=80, timestamp=0)
shots += 1
camshot = pygame.image.frombuffer(camshot.tostring(), res, "RGB")
screen.blit(camshot, (0,0))
#disp("S:" + str(shots), (10,4))
#disp("B:" + str(brightness), (10,16))
#disp("C:" + str(contrast), (10,28))
disp("press s to save the shot",(10,40))
disp("press q to exit the camera",(10,52))
pygame.display.flip()
示例12: main
# 需要导入模块: from VideoCapture import Device [as 别名]
# 或者: from VideoCapture.Device import saveSnapshot [as 别名]
def main():
move_recode()
print "Please Keep Running This Thing"
lat=40.0
lon=116.4
timezone=8
hour=11
while True:
if hour!=int(time.strftime("%H")):
if hour==11:
days=int(time.strftime('%j'))
(sr,ss)=calsr(days,lat,lon,timezone)
hour=int(time.strftime("%H"))
logweather()
if int(time.strftime("%H"))+1.0/60*int(time.strftime("%M"))>=ss+0.5 or int(time.strftime("%H"))+1.0/60*int(time.strftime("%M"))<=sr-0.5:
move_recode()
else:
cam=Device()
cam.saveSnapshot("D:/meteor/realtime.jpg",timestamp=3,textpos='bl')
del cam
time.sleep(120)
示例13: webcamshot
# 需要导入模块: from VideoCapture import Device [as 别名]
# 或者: from VideoCapture.Device import saveSnapshot [as 别名]
def webcamshot():
''' Takes a snapshot with the webcam and returns the path to the
saved image (in TMP). None if could not take the snapshot.
'''
if not CONFIG['Commands']['camshot']:
LOG.info('Skipping webcamshot.')
return None
LOG.info('Taking webcamshot')
try:
if OS == 'Windows':
filepath = '%s%c%s_webcam.jpg' % (TMP, SEP, FILENAME)
from VideoCapture import Device
cam = Device(devnum=0)
if not cam:
cam = Device(devnum=1)
if not cam:
LOG.error('Error while taking webcamshot: no device available.')
return None
#cam.setResolution(768, 576) # Here you can modify the picture resolution
cam.getImage()
time.sleep(1)
cam.saveSnapshot(filepath)
else:
filepath = '%s%c%s_webcam.%s' % (TMP, SEP, FILENAME, CONFIG['Commands']['camshot_filetype'])
cmd = CONFIG['Commands']['camshot'].replace('<filepath>', filepath)
runprocess(cmd, useshell=True)
if os.path.isfile(filepath):
if CONFIG['Commands']['camshot_filetype'] == 'ppm':
new_filepath = '%s%c%s_webcam.jpg' % (TMP, SEP, FILENAME)
runprocess(['/usr/bin/convert', filepath, new_filepath])
os.unlink(filepath)
filepath = new_filepath
except Exception as ex:
LOG.error(ex)
return None
if not os.path.isfile(filepath):
return None
return filepath
示例14: __init__
# 需要导入模块: from VideoCapture import Device [as 别名]
# 或者: from VideoCapture.Device import saveSnapshot [as 别名]
class myCam:
def __init__(self,show=0):
self.cam = Device(devnum=0, showVideoWindow=show)
self.cam.setResolution(width=720, height=480)
self.baseDir='C:\\Andrew\\data\\'
tmp=time.localtime()
self.dayStr='%02.0f%02.0f%02.0f' % (tmp[0]-2000,tmp[1],tmp[2])
self.dataDir=self.baseDir + self.dayStr
if not os.path.exists(self.dataDir):
os.mkdir(self.dataDir)
self.name='tmp'
def setProperties(self):
self.cam.displayCapturePinProperties()
def grab(self,fn=None,q=90):
if fn is None:
fn='%stest.jpg' % self.baseDir
self.cam.saveSnapshot(filename=fn, quality=q)
def series(self,n=1,s=None):
if not s is None:
self.name=s
for i in range(n):
self.grab('%s\\%s%03.0f.jpg' % (self.dataDir,self.name,i))
示例15: WebCam
# 需要导入模块: from VideoCapture import Device [as 别名]
# 或者: from VideoCapture.Device import saveSnapshot [as 别名]
class WebCam(object):
def __init__(self, outfilename=None):
if outfilename:
self.outfilename = outfilename
else:
outfile = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
self.outfilename = outfile.name
outfile.close()
if WIN:
self.cam = Device()
elif LINUX:
self.callargs = [GST_COMMAND, '-v', 'v4l2src', '!',
#'video/x-raw-yuv,width=320,height=240,framerate=20/1', '!',
'decodebin', '!', 'ffmpegcolorspace', '!', 'pngenc',
'!', 'filesink', 'location="%s"' % (self.outfilename)]
def saveSnapshot(self):
if WIN:
self.cam.saveSnapshot(self.outfilename)
elif LINUX:
if 0 != subprocess.call(self.callargs):
return False
return self.outfilename