ubuntu下使用pygame进行摄像头调用 --python
1、安装pygame模块,进入终端,输入:pip install pygame,或者:pip3 install pygame --upgrade,联网安装;
安装成功后如下图所示:
2、桌面新建.py文件,文件名为:camera.py
代码如下:
import pygame
import sys
import pygame.camera as camera
from pygame.locals import*
pygame.init()
camera.init()
screen=pygame.display.set_mode((640,480))
cam=pygame.camera.Camera("/dev/video0",(640,480))
cam.start()
while 1:
image=cam.get_image()
screen.blit(image,(0,0))
pygame.display.update()
for event in pygame.event.get():
if event.type == QUIT:
sys.exit()
在py文件所在的终端输入:python3 '/home/ant/桌面/camera.py' (换成自己的路径),终端输入python还是python3与安装时保持一致即可,完成调用。