Welcome 微信登录
编程资源 图片资源库 蚂蚁家优选 PDF转换器

首页 / 操作系统 / Linux / Python:简单的摄像头程序实现

安装了pygame,还没有具体学习如何用,先写了个最简单且原始的摄像头程序,画面还算流畅,不过还存在较多缺陷,后面对pygame熟悉了再一一优化。1、实现:[python]
  1. #!/usr/bin/env python   
  2. # -*- coding: utf-8 -*-   
  3.   
  4. from VideoCapture import Device  
  5. import time  
  6. import sys, pygame  
  7.   
  8. pygame.init()  
  9.   
  10. size = width, height = 620, 485  
  11. speed = [2, 2]  
  12. black = 0, 0, 0  
  13.   
  14. pygame.display.set_caption("视频窗口@dyx1024")   
  15. screen = pygame.display.set_mode(size)  
  16.   
  17. #抓取频率,抓取一次   
  18. SLEEP_TIME_LONG = 0.1  
  19.   
  20. #初始化摄像头   
  21. cam = Device(devnum=0, showVideoWindow=0)  
  22.       
  23. while True:  
  24.       
  25.     #抓图   
  26.     cam.saveSnapshot("test.jpg", timestamp=3, boldfont=1, quality=75)  
  27.       
  28.     #加载图像   
  29.     image = pygame.image.load("test.jpg")  
  30.       
  31.     #传送画面   
  32.     screen.blit(image, speed)  
  33.       
  34.     #显示图像   
  35.     pygame.display.flip()  
  36.     #休眠一下,等待一分钟   
  37.     time.sleep(SLEEP_TIME_LONG)  
  38.       
  39.           
2、测试