파이 게임을 통해 비디오를 보여줄 웹캠을 얻으려고합니다. 여기에 코드입니다 :이 때 나는 screen.blit (이미지, (0, 0)) 부분파이썬 파이 게임 블리트. 디스플레이 할 이미지 얻기
Traceback (most recent call last):
File "C:\Python32\src\webcam.py", line 28, in <module>
screen.blit(image, (0, 0))
TypeError: argument 1 must be pygame.Surface, not None
에서 오류가 발생
# import the relevant libraries
import time
import pygame
import pygame.camera
from pygame.locals import *
# this is where one sets how long the script
# sleeps for, between frames.sleeptime__in_seconds = 0.05
# initialise the display window
pygame.init()
pygame.camera.init()
screen = pygame.display.set_mode((640, 480), 0, 32)
# set up a camera object
cam = pygame.camera.Camera(0)
# start the camera
cam.start()
while 1:
# sleep between every frame
time.sleep(10)
# fetch the camera image
image = cam.get_image()
# blank out the screen
screen.fill((0,0,2))
# copy the camera image to the screen
screen.blit(image, (0, 0))
# update the screen to show the latest screen image
pygame.display.update()
나는하지 않았다 때문입니다 가정 파이 게임으로 작동하는 이미지로 이미지를 변환하지만, 나는 모른다.
도움이 될 것입니다. 감사합니다.
알렉스
확인 그래서 여기에 새로운 코드 : 그것은 현재 폴더에 사진을 저장하기 때문에 이 하나가 작동합니다. 마지막 한 가지 이유를 알아 냈습니다. = \
# import the relevant libraries
import time
import pygame
import pygame.camera
from pygame.locals import *
# this is where one sets how long the script
# sleeps for, between frames.sleeptime__in_seconds = 0.05
# initialise the display window
pygame.init()
pygame.camera.init()
# set up a camera object
size = (640,480)
screen = pygame.display.set_mode(size,0)
surface = pygame.surface.Surface(size,0,screen)
cam = pygame.camera.Camera(0,size)
# start the camera
cam.start()
while 1:
# sleep between every frame
time.sleep(10)
# fetch the camera image
pic = cam.get_image(surface)
# blank out the screen
#screen.fill((0,0,0))
# copy the camera image to the screen
screen.blit(pic,(0,0))
# update the screen to show the latest screen image
p=("outimage.jpg")
pygame.image.save(surface,p)
pygame.display.update()
'''cam.get_image()'''는''''''''를 돌려줍니다. – FakeRainBrigand
이 오류는 이미지가 없음이라는 것을 의미하며 잘못된 형식의 유효한 이미지가 아닙니다. cam.get_image()가 어떤 이유로 실패했습니다. – Dave