将非类型转换为Su

2024-04-25 21:28:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我的Python代码有问题。首先,当我使用函数pygame.get_image时,我的网络摄像头的屏幕截图是NoneType,但我需要它是一个表面或至少是一个图像,这样我才能转换它。这是我的密码:

    import pygame 
    import pygame.camera
    from pygame.locals import *
    pygame.init()
    pygame.camera.init()
    cam=pygame.camera.Camera(0,(640,480),"RGB")
    cam.start()

    while 1:
        screen=pygame.display.set_mode((640,480))
        im=cam.get_image()
        screen.blit(im,(0,0))
        pygame.display.update

错误信息是:

    Traceback (most recent call last):
      File "<stdin>", line 4, in <module>
    TypeError: argument 1 must be pygame.Surface, not None

Tags: 函数代码imageimport网络get屏幕init
1条回答
网友
1楼 · 发布于 2024-04-25 21:28:29

如果pygame.camera.Camera(0,(640,480),"RGB")0看起来不像设备,请尝试调用pygame.camera.list_cameras()以获取设备列表。你知道吗

请记住,此模块仅适用于带有V4L2摄像头的Linux。你知道吗

相关问题 更多 >