Merge pull request #23 from themoosman/add-setters

Add Image Settings (basic and advanced)
This commit is contained in:
Alano Terblanche
2020-10-30 20:11:16 +02:00
committed by GitHub
5 changed files with 153 additions and 7 deletions

View File

@@ -62,7 +62,7 @@ GET:
SET:
- [X] Display -> OSD
- [ ] Recording -> Encode (Clear and Fluent Stream)
- [X] Recording -> Encode (Clear and Fluent Stream)
- [ ] Recording -> Advance (Scheduling)
- [X] Network -> General
- [X] Network -> Advanced
@@ -83,5 +83,5 @@ SET:
- [x] PTZ
- [x] Zoom
- [x] Focus
- [ ] Image (Brightness, Contrast, Saturation, Hue, Sharp, Mirror, Rotate)
- [ ] Advanced Image (Anti-flicker, Exposure, White Balance, DayNight, Backlight, LED light, 3D-NR)
- [X] Image (Brightness, Contrast, Saturation, Hue, Sharp, Mirror, Rotate)
- [X] Advanced Image (Anti-flicker, Exposure, White Balance, DayNight, Backlight, LED light, 3D-NR)

View File

@@ -7,6 +7,7 @@ from .system import SystemAPIMixin
from .user import UserAPIMixin
from .ptz import PtzAPIMixin
from .alarm import AlarmAPIMixin
from .image import ImageAPIMixin
from resthandle import Request
@@ -18,7 +19,8 @@ class APIHandler(SystemAPIMixin,
RecordingAPIMixin,
ZoomAPIMixin,
PtzAPIMixin,
AlarmAPIMixin):
AlarmAPIMixin,
ImageAPIMixin):
"""
The APIHandler class is the backend part of the API, the actual API calls
are implemented in Mixins.
@@ -80,8 +82,8 @@ class APIHandler(SystemAPIMixin,
"""
try:
data = [{"cmd": "Logout", "action": 0}]
ret = self._execute_command('Logout', data)
print(ret)
self._execute_command('Logout', data)
# print(ret)
return True
except Exception as e:
print("Error Logout\n", e)

101
api/image.py Normal file
View File

@@ -0,0 +1,101 @@
class ImageAPIMixin:
"""API calls for image settings."""
def set_adv_image_settings(self,
anti_flicker='Outdoor',
exposure='Auto',
gain_min=1,
gain_max=62,
shutter_min=1,
shutter_max=125,
blue_gain=128,
red_gain=128,
white_balance='Auto',
day_night='Auto',
back_light='DynamicRangeControl',
blc=128,
drc=128,
rotation=0,
mirroring=0,
nr3d=1) -> object:
"""
Sets the advanced camera settings.
:param anti_flicker: string
:param exposure: string
:param gain_min: int
:param gain_max: string
:param shutter_min: int
:param shutter_max: int
:param blue_gain: int
:param red_gain: int
:param white_balance: string
:param day_night: string
:param back_light: string
:param blc: int
:param drc: int
:param rotation: int
:param mirroring: int
:param nr3d: int
:return: response
"""
body = [{
"cmd": "SetIsp",
"action": 0,
"param": {
"Isp": {
"channel": 0,
"antiFlicker": anti_flicker,
"exposure": exposure,
"gain": {"min": gain_min, "max": gain_max},
"shutter": {"min": shutter_min, "max": shutter_max},
"blueGain": blue_gain,
"redGain": red_gain,
"whiteBalance": white_balance,
"dayNight": day_night,
"backLight": back_light,
"blc": blc,
"drc": drc,
"rotation": rotation,
"mirroring": mirroring,
"nr3d": nr3d
}
}
}]
return self._execute_command('SetIsp', body)
def set_image_settings(self,
brightness=128,
contrast=62,
hue=1,
saturation=125,
sharpness=128) -> object:
"""
Sets the camera image settings.
:param brightness: int
:param contrast: string
:param hue: int
:param saturation: int
:param sharpness: int
:return: response
"""
body = [
{
"cmd": "SetImage",
"action": 0,
"param": {
"Image": {
"bright": brightness,
"channel": 0,
"contrast": contrast,
"hue": hue,
"saturation": saturation,
"sharpen": sharpness
}
}
}
]
return self._execute_command('SetImage', body)

View File

@@ -27,6 +27,48 @@ class RecordingAPIMixin:
body = [{"cmd": "GetRec", "action": 1, "param": {"channel": 0}}]
return self._execute_command('GetRec', body)
def set_recording_encoding(self,
audio=0,
main_bit_rate=8192,
main_frame_rate=8,
main_profile='High',
main_size="2560*1440",
sub_bit_rate=160,
sub_frame_rate=7,
sub_profile='High',
sub_size='640*480') -> object:
"""
Sets the current camera encoding settings for "Clear" and "Fluent" profiles.
:param audio: int Audio on or off
:param main_bit_rate: int Clear Bit Rate
:param main_frame_rate: int Clear Frame Rate
:param main_profile: string Clear Profile
:param main_size: string Clear Size
:param sub_bit_rate: int Fluent Bit Rate
:param sub_frame_rate: int Fluent Frame Rate
:param sub_profile: string Fluent Profile
:param sub_size: string Fluent Size
:return: response
"""
body = [{"cmd": "SetEnc",
"action": 0,
"param":
{"Enc":
{"audio": audio,
"channel": 0,
"mainStream": {
"bitRate": main_bit_rate,
"frameRate": main_frame_rate,
"profile": main_profile,
"size": main_size},
"subStream": {
"bitRate": sub_bit_rate,
"frameRate": sub_frame_rate,
"profile": sub_profile,
"size": sub_size}}
}}]
return self._execute_command('SetEnc', body)
###########
# RTSP Stream
###########

View File

@@ -66,6 +66,7 @@ setup(name=NAME,
'api.system',
'api.user',
'api.zoom',
'api.alarm'
'api.alarm',
'api.image'
]
)