我想在Windows 7机器上使用pygame模块使用Python打开相机,但是无法正常工作.我以前使用过“ / dev / video0”,它是Linux中的读取设备. pygame文档仅显示了如何在Linux中打开摄像头设备.我正在使用pygame版本1.9.1和P...

我想在Windows 7机器上使用pygame模块使用Python打开相机,但是无法正常工作.我以前使用过“ / dev / video0”,它是Linux中的读取设备. pygame文档仅显示了如何在Linux中打开摄像头设备.我正在使用pygame版本1.9.1和Python 2.7.
如何在Windows设备上打开相机?当我尝试现有脚本时,出现的错误是:
File "E:/test_python/open_cam2.py", line 10, in <module>
cam = pygame.camera.Camera("/dev/video0", (640, 480))
File "C:\Python27\lib\site-packages\pygame_camera_vidcapture.py", line 47, in init
self.dev = vidcap.new_Dev(device, show_video_window)
TypeError: an integer is required
解决方法:
尝试这个,
import pygame.camera
import pygame.image
import sys
pygame.camera.init()
cameras = pygame.camera.list_cameras()
print "Using camera %s ..." % cameras[0]
webcam = pygame.camera.Camera(cameras[0])
webcam.start()
# grab first frame
img = webcam.get_image()
WIDTH = img.get_width()
HEIGHT = img.get_height()
screen = pygame.display.set_mode( ( WIDTH, HEIGHT ) )
pygame.display.set_caption("pyGame Camera View")
while True :
for e in pygame.event.get() :
if e.type == pygame.QUIT :
sys.exit()
# draw frame
screen.blit(img, (0,0))
pygame.display.flip()
# grab next frame
img = webcam.get_image()
沃梦达教程
本文标题为:python-如何在Windows中使用pygame打开相机?


基础教程推荐
猜你喜欢
- Python+Opencv实现物体尺寸测量的方法详解 2022-10-20
- python 实现syslog 服务器的详细过程 2022-08-30
- Pecl / Python:不支持的语言环境设置-Ubuntu 13.10 2023-11-12
- python文本进度条实例 2023-08-05
- python图形界面tkinter的使用技巧 2022-10-20
- GraphLab-Create Module未安装在Python 3.5(ubuntu)上 2023-11-13
- ubuntu12.04下安装Python3.5.2 1 2023-11-11
- Python list sort方法的具体使用 2023-08-04
- 【网站】python的Windows平台的扩展包 2023-09-03
- Python + selenium 自动化测试框架详解 2023-08-04