使用Python从IP摄像机获取Onvif事件

2024-06-28 15:08:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个IP摄像头,可以发送运动事件。 使用Onvif设备管理器,我也可以看到这些事件。 但是,我无法使用Python脚本获取这些事件。 起点是Github项目:https://github.com/FalkTannhaeuser/python-onvif-zeep

如果我从documentation中正确地读取了它,那么首先您必须执行一个名为“CreatePullPointSubscriptionRequest”的函数。 作为响应,您将得到“CreatePullPointSubscriptionResponse”。 然后可以执行函数“PullMessagesRequest”

有人能给我发一个代码片段来注册一个事件(全部或过滤),然后读取事件吗

这就是我到目前为止所做的:

from onvif import ONVIFCamera
mycam = ONVIFCamera('192.168.0.2', 80, 'user', 'passwd', '/etc/onvif/wsdl/')

resp = mycam.devicemgmt.GetHostname()
print('My camera`s hostname: ' + str(resp.Name))

event_service = mycam.create_events_service()
print(event_service.GetEventProperties())

subscription = event_service.CreatePullPointSubscription()

pullpoint = mycam.create_pullpoint_service()
req = pullpoint.create_type('PullMessages') # Exception: No element 'PullMessages' in namespace http://docs.oasis-open.org/wsrf/rw-2. Available elements are:  - 
req.MessageLimit=100
print(pullpoint.PullMessages(req))

Tags: 函数ipeventcreateservice事件reqresp