-
Notifications
You must be signed in to change notification settings - Fork 6
/
camera.py
executable file
·98 lines (88 loc) · 4.33 KB
/
camera.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
# Copyright 2019 Kent A. Vander Velden <[email protected]>
#
# If you use this software, please consider contacting me. I'd like to hear
# about your work.
#
# This file is part of Haimer-Probe.
#
# Haimer-Probe is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Haimer-Probe is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Haimer-Probe. If not, see <https://www.gnu.org/licenses/>.
import sys
# noinspection PyUnresolvedReferences
import cv2
def list_camera_properties(video_cap):
capture_properties = [('cv2.CAP_PROP_POS_MSEC', True),
('cv2.CAP_PROP_POS_FRAMES', False),
('cv2.CAP_PROP_POS_AVI_RATIO', False),
('cv2.CAP_PROP_FRAME_WIDTH', True),
('cv2.CAP_PROP_FRAME_HEIGHT', True),
('cv2.CAP_PROP_FPS', True),
('cv2.CAP_PROP_FOURCC', True),
('cv2.CAP_PROP_FRAME_COUNT', False),
('cv2.CAP_PROP_FORMAT', True),
('cv2.CAP_PROP_MODE', True),
('cv2.CAP_PROP_BRIGHTNESS', True),
('cv2.CAP_PROP_CONTRAST', True),
('cv2.CAP_PROP_SATURATION', True),
('cv2.CAP_PROP_HUE', False),
('cv2.CAP_PROP_GAIN', False),
('cv2.CAP_PROP_EXPOSURE', True),
('cv2.CAP_PROP_CONVERT_RGB', True),
('cv2.CAP_PROP_WHITE_BALANCE_BLUE_U', False),
('cv2.CAP_PROP_RECTIFICATION', False),
('cv2.CAP_PROP_MONOCHROME', False),
('cv2.CAP_PROP_SHARPNESS', True),
('cv2.CAP_PROP_AUTO_EXPOSURE', True),
('cv2.CAP_PROP_GAMMA', False),
('cv2.CAP_PROP_TEMPERATURE', True),
('cv2.CAP_PROP_TRIGGER', False),
('cv2.CAP_PROP_TRIGGER_DELAY', False),
('cv2.CAP_PROP_WHITE_BALANCE_RED_V', False),
('cv2.CAP_PROP_ZOOM', True),
('cv2.CAP_PROP_FOCUS', True),
('cv2.CAP_PROP_GUID', False),
('cv2.CAP_PROP_ISO_SPEED', False),
('cv2.CAP_PROP_BACKLIGHT', True),
('cv2.CAP_PROP_PAN', True),
('cv2.CAP_PROP_TILT', True),
('cv2.CAP_PROP_ROLL', False),
('cv2.CAP_PROP_IRIS', False),
('cv2.CAP_PROP_SETTINGS', False),
('cv2.CAP_PROP_BUFFERSIZE', True),
('cv2.CAP_PROP_AUTOFOCUS', True),
('cv2.CAP_PROP_SAR_NUM', False),
('cv2.CAP_PROP_SAR_DEN', False),
('cv2.CAP_PROP_BACKEND', True),
('cv2.CAP_PROP_CHANNEL', True),
('cv2.CAP_PROP_AUTO_WB', True),
('cv2.CAP_PROP_WB_TEMPERATURE', True)
]
for nm, v in capture_properties:
if v:
print(nm, video_cap.get(eval(nm)))
def set_camera_properties(video_cap, res):
if res == '1280x720':
capture_properties = [('cv2.CAP_PROP_FRAME_WIDTH', 1280),
('cv2.CAP_PROP_FRAME_HEIGHT', 720)
]
elif res == '640x480':
capture_properties = [('cv2.CAP_PROP_FRAME_WIDTH', 640),
('cv2.CAP_PROP_FRAME_HEIGHT', 480)
]
else:
print('Unknown res', res)
sys.exit(1)
for nm, v in capture_properties:
if not video_cap.set(eval(nm), v):
print('Unable to set', nm, v)