python ONVIF在相机上旋转视频源



我正试图通过Python ONVIF旋转所有ONVIF配置文件的视频源。我使用的是Python 3.8.1和onvif_zeep库:这是这个库的链接

在阅读了ONVIF主页上的文档后,我不清楚如何做到这一点。

我使用以下代码:

from onvif import ONVIFCamera
mycam = ONVIFCamera(Cam_ip,80,Onvif_User,Onvif_User_Pass) # the connection is done ok
media = mycam.create_media_service() # Media Service is ok
#Get The video source configurations
configurations_list = media.GetVideoSourceConfigurations() # Ok I get the Video Source configuration I wanted to select on id 0
video_source_configuration = configurations_list[0]

好的,现在我已经将视频源存储在video_source_configuration中。如果我打印它,我可以正确地获得信息:

{
'Name': 'SOURCE_VIDEO',
'UseCount': 5,
'SourceToken': '0',
'Bounds': {
'x': 0,
'y': 0,
'width': 1820,
'height': 720
},
'_value_1': None,
'Extension': None,
'token': '0',
'_attr_1': {
}
}

即使我修改例如宽度或高度,我也可以在没有问题的情况下进行此操作

video_source_configuration.width = 640
video_source_configuration.height = 420
request = media.create_type('SetVideoSourceConfiguration')
request.Configuration = video_source_configuration
request.ForcePersistence = True
media.SetVideoSourceConfiguration(request)

但我不知道如何修改Video_Source_Configuration使其旋转90或270度。我已经阅读了函数media.GetVideoSourceConfigurationOptios(),并得到了以下响应:

{
'BoundsRange': {
'XRange': {
'Min': 0,
'Max': 1280
},
'YRange': {
'Min': 0,
'Max': 720
},
'WidthRange': {
'Min': 0,
'Max': 1280
},
'HeightRange': {
'Min': 0,
'Max': 720
}
},
'VideoSourceTokensAvailable': [
'0'
],
'Extension': {
'_value_1': [
<Element {http://www.onvif.org/ver10/schema}Rotate at 0x243b6f4d2c0>
],
'Rotate': None,
'Extension': None
},
'_attr_1': None
}

我想我需要修改Extension字段和Rotate属性,但阅读文档时我不知道该怎么做

最后我用python 2.7和python onvif库解决了这个问题

要选择"旋转"模式,您应该使用sux库中的Text类。

因此,以下代码运行良好,相机可以正确旋转所有ONVIF流:

from onvif import ONVIFCamera
from suds.sax.text import Text
mycam = ONVIFCamera(Cam_ip,80,Onvif_User,Onvif_User_Pass) 
media = mycam.create_media_service()
#Get The video source configurations
configurations_list = media.GetVideoSourceConfigurations() 
video_source_configuration = configurations_list[0]
request = media.create_type('SetVideoSourceConfiguration')
request.Configuration.Name = video_source_configuration.Name 
request.Configuration.UseCount = video_source_configuration.UseCount request.Configuration._token = video_source_configuration._token 
request.Configuration.Bounds = video_source_configuration.Bounds
request.Configuration.SourceTokens = video_source_configuration.SourceTokens
#Now we perform a rotation of all ONVIF streams 90 Degrees.
request.Configuration.Extension.Rotate.Mode.value=Text(u'ON')
request.Configuration.Extension.Rotate.Degree = 90
#Add persistence to store the configuration in non volatile Memory
request.ForcePersistence = True

media.SetVideoSourceConfiguration(request)

它是有效的,但对于python 2和python 3,我目前还没有找到解决方案。

最新更新