本文將介紹如何呼叫onvif協議的介面,來實現**控制海康相機雲台轉動,查詢的大多數**是使用c++來實現,感覺有點複雜,本文直接採用python介面來實現。終端輸入以下**:
安裝成功後,執行python2,輸入以下語句,不報錯即安裝成功
from onvif import onvifcamera
在python-onvif安裝包中,有examples資料夾,其中有個continuous_move.py檔案,**如下:
from time import sleep
from onvif import onvifcamera
xmax =
1xmin =-1
ymax =
1ymin =-1
defperform_move
(ptz, request, timeout)
:# start continuous move
ptz.continuousmove(request)
# wait a certain time
sleep(timeout)
# stop continuous move
ptz.stop(
)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)
defmove_down
(ptz, request, timeout=1)
:print
'move down...'
request.velocity.pantilt._x =
0 request.velocity.pantilt._y = ymin
perform_move(ptz, request, timeout)
defmove_right
(ptz, request, timeout=1)
:print
'move right...'
request.velocity.pantilt._x = xmax
request.velocity.pantilt._y =
0 perform_move(ptz, request, timeout)
defmove_left
(ptz, request, timeout=1)
:print
'move left...'
request.velocity.pantilt._x = xmin
request.velocity.pantilt._y =
0 perform_move(ptz, request, timeout)
defcontinuous_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(
)# 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(
)
將第43行函式裡的ip、使用者名稱、密碼修改為自己相機的引數,比如我的相機引數如下:
mycam = onvifcamera(
'192.168.0.141',80
,'admin'
,'**'
)
首先:
$ sudo
apt-get
install python-pygame
然後執行
$ python continuous_move.py
相機雲台即可分別實現右左上下運動,參考此**我們便可以編寫我們自己的運動控制程式。 python onvif庫基本使用
最近新專案中要把一套現有的系統移植到華為atlas終端上,因為現在這套系統裡關於攝像頭預置位跳轉,抓圖等功能是呼叫海康sdk實現的 但是atlas終端是arm平台的,海康的sdk是x86平台的,並沒有提供arm版本的,所以考慮使用onvif協議實現預置位跳轉和抓圖功能,這樣就不用考慮平台差異了。on...
OAF實現客戶化查詢
在oaf中,存在標準的查詢面板,但是標準的查詢只能實現基礎 簡單的查詢,所以在真正的專案當中,一般情況下都是使用自己開發的客戶化查詢,開發客戶化查詢的一般步驟如下 1.建立頁面pg,修改regionid pagelayoutrn region style pagelayout am definiti...
實現UDP客戶端
實現udp客戶端 1 基於連線和無連線 2 對系統資源的要求 tcp多,udp少 3 udp程式結構較簡單 4 流模式與資料報模式 5 tcp保證資料準確性,udp可能丟包,tcp保證資料順序,udp不保證 import socket if name main 1.建立udp客戶端,建立套接字 ud...