image capture from camera and saving the image

Solutions on MaxInterview for image capture from camera and saving the image by the best coders in the world

showing results for - "image capture from camera and saving the image"
Maeva
12 Aug 2017
1import cv2 
2# Open the device at the ID 0
3
4cap = cv2.VideoCapture(0)
5
6#Check whether user selected camera is opened successfully.
7
8if not (cap.isOpened()):
9
10print(“Could not open video device”)
11
12#To set the resolution
13
14cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 640)
15
16cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 480)
17
18while(True):
19
20# Capture frame-by-frame
21
22ret, frame = cap.read()
23
24# Display the resulting frame
25
26cv2.imshow(‘preview’,frame)
27
28#Waits for a user input to quit the application
29
30if cv2.waitKey(1) & 0xFF == ord(‘q’):
31
32break
33
34# When everything done, release the capture
35
36cap.release()
37
38cv2.destroyAllWindows()