2015-09-20 147 views
0

我正在使用pygame來捕捉圖像,而我似乎無法弄清楚它的正確性。附加的圖像,正如你可以看到圖像被分割中間。PyGame Saving Webcam,圖像分割

這裏是源代碼:

def getImg(fname): 
    pygame.camera.init() 
    cm = pygame.camera.list_cameras() 
    cam = pygame.camera.Camera(cm[0]) 
    cam.start() 
    img = cam.get_image() 
    pygame.image.save(img,fname) 
    cam.stop() 

Image I have a problem with

+0

如果我用應用程序初始化相機,從而給它加載幾秒鐘,圖像加載正常,但我不想讓相機在整個時間運行。 – triunenature

回答

0

好了,我發現周圍的工作,我張貼,因爲它可能會在未來有用:

def saveImage(fname): 
    pygame.camera.init() 
    cam_list = pygame.camera.list_cameras() 
    cam = pygame.camera.Camera(cam_list[0]) 
    cam.start() 
    ## the duplicate get_image(): 
    ## the first one gets the camera working, 
    ## the second captures a clean image 
    cam.get_image() 
    cam.get_image() 
    img = cam.get_image() 
    pygame.image.save(img,fname) 
    cam.stop()