python 简单照相机调用系统摄像头实现方法 pygame

yipeiwu_com6年前Python基础

如下所示:

# -*- coding: utf-8 -*- 
 
 
from VideoCapture import Device 
import time 
import pygame 
from pygame.locals import *
import sys
 
 
pygame.init() 
 
size = width, height = 620, 485 
print size
speed = [2, 2] 
black = 0, 0, 0 
if pygame.display.get_init():
 print ("inited")
else:
 print"notinit"
pygame.display.set_caption('1111') 
screen = pygame.display.set_mode((600,500))
 
 
SLEEP_TIME_LONG = 0.0
 
 
cam = Device(devnum=0, showVideoWindow=0) 
print cam  
filename = "test.jpg"
while True: 
 for event in pygame.event.get():
   if event.type== QUIT:
    sys.exit()
   elif event.type== KEYDOWN:
    key = pygame.key.get_pressed()
    if key[97]:
     filename = "test" + int(time.time()//1).__str__()+".jpg"
     print filename
     cam.saveSnapshot(filename, timestamp=3, boldfont=1, quality=55) 
   elif event.type== MOUSEBUTTONDOWN:
    pass
   elif event.type== MOUSEMOTION:
    pass
   elif event.type== MOUSEBUTTONUP:
    pass
  
 
 
  #cam.getImage(0, 0, "bl")
 
 cmd="shut"
 Image = pygame.image.load(filename)
 #screen.fill(0,0,200)
 screen.blit(Image, (0,0))
 pygame.display.update()
 
  
 
 
 time.sleep(SLEEP_TIME_LONG) 

以上这篇python 简单照相机调用系统摄像头实现方法 pygame就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python实现上传下载文件功能

最近刚学python,遇到上传下载文件功能需求,记录下! django web项目,前端上传控件用的是uploadify。 文件上传 - 后台view 的 Python代码如下: @...

Python 经典算法100及解析(小结)

1:找出字符串s="aaabbbccceeefff111144444"中,字符出现次数最多的字符 (1)考虑去重,首先将字符串进行过滤去重,这样在根据这些字符进行循环查询时,将会减少循...

数据清洗--DataFrame中的空值处理方法

数据清洗是一项复杂且繁琐的工作,同时也是整个数据分析过程中最为重要的环节。 在python中空值被显示为NaN。首先,我们要构造一个包含NaN的DataFrame对象。 >&g...

python学习手册中的python多态示例代码

在处理多态对象时,只需要关注它的接口即可,python中并不需要显示的编写(像Java一样)接口,在使用对象的使用先假定有该接口,如果实际并不包含,在运行中报错。复制代码 代码如下:cl...

使用Python进行AES加密和解密的示例代码

高级加密标准(英语:Advanced Encryption Standard,缩写:AES),在密码学中又称Rijndael加密法,是美国联邦政府采用的一种区块加密标准。这个标准用来替代...