-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaptureImages.py
More file actions
executable file
·42 lines (34 loc) · 981 Bytes
/
captureImages.py
File metadata and controls
executable file
·42 lines (34 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import numpy as np
import cv2
import glob
cam = cv2.VideoCapture(0)
cam.set(3,640)
cam.set(4,480)
ret, frame = cam.read()
h, w = frame.shape[:2]
print("Start Capturing")
cntr = 0
while True:
ret, frame = cam.read()
frame = cv2.flip(cv2.flip(frame,1),-1)
cv2.imshow("Frames", frame)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Find the chess board corners
ret, corners = cv2.findChessboardCorners(gray, (7, 9), None)
# If found, add object points, image points (after refining them)
key = cv2.waitKey(33)
if key == 1048689 or key == 113: # q
break
elif key == 1048608or key == 32: # space
if ret:
# Capture image
cntr += 1
filename = "Image"+str(cntr)+".png"
print("Writing", filename)
cv2.imwrite(filename,frame)
else:
print("Failed to find chessboard")
elif key != -1:
print(key)
cv2.destroyAllWindows()
cam.release()