import cv2
camera_port=0#camera number
camera = cv2.VideoCapture(camera_port)#simply activates the camera section
for i in xrange(30): #avoides first 30 images
retval, f= camera.read()
while True:
cv2.imshow(“preview”, f)
retval, f = camera.read()
if cv2.waitKey(1)== 48: # ascii code of number 0
cv2.destroyAllWindows()
break
cv2.imwrite(“test1.jpg”,f)
cv2.imshow(‘image’,f)
cv2.waitKey(0)
cv2.destroyAllWindows()
del(camera)