Skip to content

Commit d84ec91

Browse files
author
Alano Terblanche
authored
Merge pull request #13 from burrscurr/master
Implement calls for zooming and focusing
2 parents 2124725 + eeb6189 commit d84ec91

File tree

5 files changed

+136
-8
lines changed

5 files changed

+136
-8
lines changed

Pipfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ verify_ssl = true
99
pillow = "*"
1010
pyyaml = "*"
1111
requests = "*"
12+
numpy = "*"
13+
opencv-python = "*"
14+
pysocks = "*"
1215

1316
[requires]

Pipfile.lock

Lines changed: 71 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ SET:
7373
- [ ] User -> Add User
7474
- [ ] User -> Manage User
7575
- [ ] Device -> HDD/SD Card
76-
- [ ] Zoom
77-
- [ ] Focus
76+
- [x] Zoom
77+
- [x] Focus
7878
- [ ] Image (Brightness, Contrass, Saturation, Hue, Sharp, Mirror, Rotate)
7979
- [ ] Advanced Image (Anti-flicker, Exposure, White Balance, DayNight, Backlight, LED light, 3D-NR)

api/APIHandler.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from api.recording import RecordingAPIMixin
1+
from .recording import RecordingAPIMixin
2+
from .zoom import ZoomAPIMixin
23
from .device import DeviceAPIMixin
34
from .display import DisplayAPIMixin
45
from .network import NetworkAPIMixin
@@ -12,7 +13,8 @@ class APIHandler(SystemAPIMixin,
1213
UserAPIMixin,
1314
DeviceAPIMixin,
1415
DisplayAPIMixin,
15-
RecordingAPIMixin):
16+
RecordingAPIMixin,
17+
ZoomAPIMixin):
1618
"""
1719
The APIHandler class is the backend part of the API, the actual API calls
1820
are implemented in Mixins.

api/zoom.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
class ZoomAPIMixin:
2+
"""
3+
API for zooming and changing focus.
4+
Note that the API does not allow zooming/focusing by absolute
5+
values rather that changing focus/zoom for a given time.
6+
"""
7+
def _start_operation(self, operation, speed):
8+
data = [{"cmd": "PtzCtrl", "action": 0, "param": {"channel": 0, "op": operation, "speed": speed}}]
9+
return self._execute_command('PtzCtrl', data)
10+
11+
def _stop_zooming_or_focusing(self):
12+
"""This command stops any ongoing zooming or focusing actions."""
13+
data = [{"cmd": "PtzCtrl", "action": 0, "param": {"channel": 0, "op": "Stop"}}]
14+
return self._execute_command('PtzCtrl', data)
15+
16+
def start_zooming_in(self, speed=60):
17+
"""
18+
The camera zooms in until self.stop_zooming() is called.
19+
:return: response json
20+
"""
21+
return self._start_operation('ZoomInc', speed=speed)
22+
23+
def start_zooming_out(self, speed=60):
24+
"""
25+
The camera zooms out until self.stop_zooming() is called.
26+
:return: response json
27+
"""
28+
return self._start_operation('ZoomDec', speed=speed)
29+
30+
def stop_zooming(self):
31+
"""
32+
Stop zooming.
33+
:return: response json
34+
"""
35+
return self._stop_zooming_or_focusing()
36+
37+
def start_focusing_in(self, speed=32):
38+
"""
39+
The camera focuses in until self.stop_focusing() is called.
40+
:return: response json
41+
"""
42+
return self._start_operation('FocusInc', speed=speed)
43+
44+
def start_focusing_out(self, speed=32):
45+
"""
46+
The camera focuses out until self.stop_focusing() is called.
47+
:return: response json
48+
"""
49+
return self._start_operation('FocusDec', speed=speed)
50+
51+
def stop_focusing(self):
52+
"""
53+
Stop focusing.
54+
:return: response json
55+
"""
56+
return self._stop_zooming_or_focusing()

0 commit comments

Comments
 (0)