因此,我在Pygame中下载了Video Capture的窗轮。但是,当我创建网络摄像头实例时,出现以下错误。在我开始实现相机模块之前,代码运行良好。我看到的答案很少,它们来自2013年。我希望Pygame从那时起在Windows上会有更多的改进,但是最有可能是由我引起的。有什么建议吗?
import pygame
import pygame.camera
pygame.init()
# https://www.lfd.uci.edu/~gohlke/pythonlibs/#videocapture need to get the VideoCapture whl
pygame.camera.init()
webcam = pygame.camera.Camera(0, (640, 480), "RGB")
webcam.start()
pygame.display.set_caption("S.H.A.N.E.")
icon = pygame.image.load("SHANE pic.jpg")
pygame.display.set_icon(icon)
background = pygame.image.load("SHANE pic.jpg")
# (WIDTH, HEIGHT)
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
running = True
while running:
# STARTING POINT (L/R, T/B), ENDING POINT (L/R, T/B)
screen.fill((0, 0, 0))
img = webcam.get_image()
screen.blit(img, (0, 0))
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
这是我遇到的错误。
Traceback (most recent call last): File "C:/Users/Notebook/PycharmProjects/Jarvis/Gui2.py", line 10, in <module> webcam = pygame.camera.Camera(0, (640, 480), "RGB") File "C:\Users\Notebook\AppData\Local\Programs\Python\Python37-32\lib\site-<packages\pygame\_camera_vidcapture.py", line 60, in __init__ self.dev.setresolution(width, height) vidcap.Error: Cannot set capture resolution.
webcam = pygame.camera.Camera("/dev/video0",(640,480))
您没有将相机的坐标/大小/比例放置在放置它们的位置,这是为文件输入保留的。干杯!文件:https://www.pygame.org/docs/tut/CameraIntro.html