get numpy array from pygame
Question: I want to access my Webcam via python. Unfortunately openCV is not working
because of the webcam. Pygame.camera works like a charm with this code:

    
    
    from pygame import camera,display
    
    camera.init()
    webcam = camera.Camera(camera.list_cameras()[0])
    webcam.start()
    
    img = webcam.get_image()
    
    screen = display.set_mode((img.get_width(), img.get_height()))
    display.set_caption("cam")
    
    while True:
        screen.blit(img, (0,0))
        display.flip()   
        img = webcam.get_image()
    

My question is now, how can I get a numpy array from the webcam?


Answer: `get_image` returns a
[`Surface`](http://www.pygame.org/docs/ref/surface.html). According to
<http://www.pygame.org/docs/ref/surfarray.html>, you can use
`pygame.surfarray.array2d` (or one of the other functions in the `surfarray`
module) to convert the Surface to a numpy array. E.g.

    
    
        img = webcam.get_image()
        data = pygame.surfarray.array2d(img)
    

