This article has participated in 「 New people's creation ceremony 」 Activities , Start the road of nuggets creation together .
Used all the time go Way to search the camera 、 Change network address 、 obtain media、ptz as well as preset etc. , But the current test go Your library is not working properly on some cameras ptz, So I'm analyzing c/c++ Library and python The library , I'm going to test python The library of , Use python stay pip Can be installed directly in onvif Bag can , It's easy to write , Most of the interfaces are implemented , Compare with go My bag is more mature , Compare with c++ The way to get started faster , So at present, search and change the network are still used go,ptz etc. go Where the implementation is not good, pass parameters to python Script to do it , Wait until you have kung fu go Modify your package (python The package display seems to be difficult to handle , So it's not all switched to python).
Address , Currently in 0.2.0 edition , It seems that it hasn't been updated for some time :
github.com/quatanium/p…
You can use it directly pip install , This applies to python2 Of , It also provides for python3 The address of :github.com/FalkTannhae…
install python2.7:
opkg update
opkg install python2.7
install pip:
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py --no-check-certificate
python2.7 get-pip.py
install python-onvif:
pip install onvif
as follows , It's also used continuousMove, This is an official example , You can use it directly :
from time import sleep
from onvif import ONVIFCamera
XMAX = 1
XMIN = -1
YMAX = 1
YMIN = -1
def perform_move(ptz, request, timeout):
# Start continuous move
ptz.ContinuousMove(request)
# Wait a certain time
sleep(timeout)
# Stop continuous move
ptz.Stop({'ProfileToken': request.ProfileToken})
def move_up(ptz, request, timeout=1):
print 'move up...'
request.Velocity.PanTilt._x = 0
request.Velocity.PanTilt._y = YMAX
perform_move(ptz, request, timeout)
def move_down(ptz, request, timeout=1):
print 'move down...'
request.Velocity.PanTilt._x = 0
request.Velocity.PanTilt._y = YMIN
perform_move(ptz, request, timeout)
def move_right(ptz, request, timeout=1):
print 'move right...'
request.Velocity.PanTilt._x = XMAX
request.Velocity.PanTilt._y = 0
perform_move(ptz, request, timeout)
def move_left(ptz, request, timeout=1):
print 'move left...'
request.Velocity.PanTilt._x = XMIN
request.Velocity.PanTilt._y = 0
perform_move(ptz, request, timeout)
def continuous_move():
mycam = ONVIFCamera('192.168.0.112', 80, 'admin', '12345')
# Create media service object
media = mycam.create_media_service()
# Create ptz service object
ptz = mycam.create_ptz_service()
# Get target profile
media_profile = media.GetProfiles()[0];
# Get PTZ configuration options for getting continuous move range
request = ptz.create_type('GetConfigurationOptions')
request.ConfigurationToken = media_profile.PTZConfiguration._token
ptz_configuration_options = ptz.GetConfigurationOptions(request)
request = ptz.create_type('ContinuousMove')
request.ProfileToken = media_profile._token
ptz.Stop({'ProfileToken': media_profile._token})
# Get range of pan and tilt
# NOTE: X and Y are velocity vector
global XMAX, XMIN, YMAX, YMIN
XMAX = ptz_configuration_options.Spaces.ContinuousPanTiltVelocitySpace[0].XRange.Max
XMIN = ptz_configuration_options.Spaces.ContinuousPanTiltVelocitySpace[0].XRange.Min
YMAX = ptz_configuration_options.Spaces.ContinuousPanTiltVelocitySpace[0].YRange.Max
YMIN = ptz_configuration_options.Spaces.ContinuousPanTiltVelocitySpace[0].YRange.Min
# move right
move_right(ptz, request)
# move left
move_left(ptz, request)
# Move up
move_up(ptz, request)
# move down
move_down(ptz, request)
if __name__ == '__main__':
continuous_move()
No such file: /usr/lib/python2.7/site-packages/wsdl/devicemgmt.wsdl
resolvent :
github.com/FalkTannhae…
Appoint wsdl Address and location :
have access to find Command find wsdl Just place :
find / -name *.wsdl
So here I am pip install onvif After the default wsdl stay /usr/ Next :