Python:简单的摄像头程序实现

来源:互联网 发布:oppo结构工程师pe 知乎 编辑:程序博客网 时间:2024/05/16 00:46

  昨天安装了pygame,还没有具体学习如何用,先写了个最简单且原始的摄像头程序,画面还算流畅,不过还存在较多缺陷,后面对pygame熟悉了再一一优化。

  1、实现:

#!/usr/bin/env python# -*- coding: utf-8 -*-from VideoCapture import Deviceimport timeimport sys, pygamepygame.init()size = width, height = 620, 485speed = [2, 2]black = 0, 0, 0pygame.display.set_caption('视频窗口@dyx1024') screen = pygame.display.set_mode(size)#抓取频率,抓取一次SLEEP_TIME_LONG = 0.1#初始化摄像头cam = Device(devnum=0, showVideoWindow=0)    while True:        #抓图    cam.saveSnapshot('test.jpg', timestamp=3, boldfont=1, quality=75)        #加载图像    image = pygame.image.load('test.jpg')        #传送画面    screen.blit(image, speed)        #显示图像    pygame.display.flip()    #休眠一下,等待一分钟    time.sleep(SLEEP_TIME_LONG)            

2、测试


原创粉丝点击