-
Notifications
You must be signed in to change notification settings - Fork 39
/
camera_test.py
83 lines (70 loc) · 2.53 KB
/
camera_test.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
import numpy as np
import time
import cv2
# cap = cv2.VideoCapture(0)
camera_index = 0
def test_cam():
#capture from camera at location 0
cap = cv2.VideoCapture(camera_index)
# Change the camera setting using the set() function
cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 320)
cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 240)
# cap.set(cv2.cv.CV_CAP_PROP_FPS, 60)
# cap.set(cv2.cv.CV_CAP_PROP_EXPOSURE, -6.0)
# cap.set(cv2.cv.CV_CAP_PROP_GAIN, 4.0)
# cap.set(cv2.cv.CV_CAP_PROP_BRIGHTNESS, 144.0)
# cap.set(cv2.cv.CV_CAP_PROP_CONTRAST, 27.0)
# cap.set(cv2.cv.CV_CAP_PROP_HUE, 13.0) # 13.0
# cap.set(cv2.cv.CV_CAP_PROP_SATURATION, 28.0)
# Read the current setting from the camera
test = cap.get(cv2.cv.CV_CAP_PROP_POS_MSEC)
ratio = cap.get(cv2.cv.CV_CAP_PROP_POS_AVI_RATIO)
frame_rate = cap.get(cv2.cv.CV_CAP_PROP_FPS)
width = cap.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)
height = cap.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)
brightness = cap.get(cv2.cv.CV_CAP_PROP_BRIGHTNESS)
contrast = cap.get(cv2.cv.CV_CAP_PROP_CONTRAST)
saturation = cap.get(cv2.cv.CV_CAP_PROP_SATURATION)
hue = cap.get(cv2.cv.CV_CAP_PROP_HUE)
gain = cap.get(cv2.cv.CV_CAP_PROP_GAIN)
exposure = cap.get(cv2.cv.CV_CAP_PROP_EXPOSURE)
print("Test: ", test)
print("Ratio: ", ratio)
print("Frame Rate: ", frame_rate)
print("Height: ", height)
print("Width: ", width)
print("Brightness: ", brightness)
print("Contrast: ", contrast)
print("Saturation: ", saturation)
print("Hue: ", hue)
print("Gain: ", gain)
print("Exposure: ", exposure)
while True:
start_time = time.time()
ret, img = cap.read()
cv2.imshow("input", img)
file = "out/fast+%s.png" % start_time
# A nice feature of the imwrite method is that it will automatically choose the
# correct format based on the file extension you provide. Convenient!
cv2.imwrite(file, img)
end_time = time.time()
seconds = end_time - start_time
print "Time: {0} seconds".format(seconds)
# time.sleep(0.001)
key = cv2.waitKey(10)
if key == 27:
break
cv2.destroyAllWindows()
cv2.VideoCapture(camera_index).release()
test_cam()
# while(True):
# # Capture frame-by-frame
# ret, frame = cap.read()
# print type(frame)
# im = Image.fromarray(frame)
# im.save("out.png")
# time.sleep(1)
# # When everything done, release the capture
# cap.release()
# cv2.destroyAllWindows()