CAPTURING AN IMAGE FROM CAMERA USING PYTHON AND OPEN CV

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()

cv2.imwrite("test1.jpg",f)
cv2.imshow('image',f)
cv2.waitKey(0)
cv2.destroyAllWindows()
del(camera)