Refer GCP/Docker/docker-webcam for more details
import pygame
import pygame.camera as cm
cm.init()
cm.list_cameras()
cam = cm.Camera(cm.list_cameras()[0])
cam.start()
img = cam.get_image()
img
cam.stop()
#Convert to numpy array
#The height and width are swapped
imgdata = pygame.surfarray.array3d(img)
imgdata
imgdata.shape
import matplotlib.pyplot as plt
%matplotlib inline
#image dimensions are swapped
plt.imshow(imgdata)
plt.imshow(imgdata.swapaxes(0,1)) #Can also use transpose (1,0,2)