-
Notifications
You must be signed in to change notification settings - Fork 0
/
testcam.py
58 lines (44 loc) · 1.3 KB
/
testcam.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import cv2
from matplotlib import pyplot as plt
import sys
WIDTH, HEIGHT = 1280, 720
#WIDTH, HEIGHT = 352, 288
if len(sys.argv) > 1:
id = int(sys.argv[1])
else:
id = 0
cap = cv2.VideoCapture(id)
#Check if camera was opened correctly
if not (cap.isOpened()):
print("Could not open video device")
exit()
#Set the resolution
cap.set(cv2.CAP_PROP_FRAME_WIDTH, WIDTH)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, HEIGHT)
#v4l2-ctl -d /dev/video0 -c exposure_auto=1 -c exposure_auto_priority=0 -c exposure_absolute=500
# cap.set(cv2.CAP_PROP_AUTO_EXPOSURE, 1)
# cap.set(cv2.CAP_PROP_EXPOSURE, 1)
# print(cap.get(cv2.CAP_PROP_EXPOSURE))
need_creating_window = True
# Capture frame-by-frame
while(True):
ret, frame = cap.read()
# Display the resulting frame
cv2.imshow("preview",frame)
plt.clf()
plt.plot(frame[310,:])
if need_creating_window:
plt.show(block=False)
need_creating_window = False
else:
plt.draw()
# cv2.imwrite("outputImage.jpg", frame)
#print(type(frame), ret)
sharpness = cv2.Laplacian(frame, cv2.CV_64F).var()
print(sharpness)
#Waits for a user input to quit the application
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()