first commit
This commit is contained in:
1 parent
ae53e9eac5
commit
91cbd01126
514 files changed
+55625
-2203
No files matched your search
Executable
+179
@@ -0,0 +1,179 @@
|
||||
import json
|
||||
import time
|
||||
|
||||
import zeep
|
||||
from onvif import ONVIFCamera
|
||||
|
||||
|
||||
|
||||
hangshu =7
|
||||
lieshu = 60
|
||||
#cv2.namedWindow("AI-ECO",cv2.WINDOW_FREERATIO)#WINDOW_FREERATIO
|
||||
record_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
|
||||
def zeep_pythonvalue(self, xmlvalue):
|
||||
return xmlvalue
|
||||
|
||||
|
||||
class Onvif_hik(object):
|
||||
|
||||
def __init__(self, ip: str, username: str, password: str):
|
||||
self.ip = ip
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.save_path = "./{}T{}.jpg".format(self.ip, str(time.time())) # ½ØÍ¼±£´æÂ·¾¶
|
||||
self.content_cam()
|
||||
|
||||
def content_cam(self):
|
||||
"""
|
||||
Á´½ÓÏà»úµØÖ·
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
self.mycam = ONVIFCamera(self.ip,1024 , self.username, self.password)
|
||||
self.media = self.mycam.create_media_service() # ´´½¨Ã½Ìå·þÎñ
|
||||
# µÃµ½Ä¿±ê¸ÅÒªÎļþ
|
||||
zeep.xsd.simple.AnySimpleType.pythonvalue = zeep_pythonvalue
|
||||
self.media_profile = self.media.GetProfiles()[0] # »ñÈ¡ÅäÖÃÐÅÏ¢
|
||||
self.ptz = self.mycam.create_ptz_service() # ´´½¨¿ØÖÆÌ¨·þÎñ
|
||||
return True
|
||||
except Exception as e:
|
||||
return False
|
||||
|
||||
def Snapshot(self):
|
||||
"""
|
||||
½ØÍ¼
|
||||
:return:
|
||||
"""
|
||||
res = self.media.GetSnapshotUri({'ProfileToken': self.media_profile.token})
|
||||
|
||||
response = requests.get(res.Uri, auth=HTTPDigestAuth(self.username, self.password))
|
||||
with open(self.save_path, 'wb') as f: # ±£´æ½ØÍ¼
|
||||
f.write(response.content)
|
||||
|
||||
def get_presets(self):
|
||||
"""
|
||||
»ñȡԤÖõãÁбí
|
||||
:return:Ô¤ÖõãÁбí--ËùÓеÄÔ¤Öõã
|
||||
"""
|
||||
presets = self.ptz.GetPresets({'ProfileToken': self.media_profile.token}) # »ñÈ¡ËùÓÐÔ¤Öõã,·µ»ØÖµ£ºlist
|
||||
return presets
|
||||
|
||||
def goto_preset(self, presets_token: int):
|
||||
"""
|
||||
ÒÆ¶¯µ½Ö¸¶¨Ô¤Öõã
|
||||
:param presets_token: Ä¿µÄλÖõÄtoken£¬»ñȡԤÖõ㷵»ØÖµÖÐ
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
# self.ptz.GotoPreset(
|
||||
# {'ProfileToken': self.media_profile.token, "PresetToken": presets_token}) # ÒÆ¶¯µ½Ö¸¶¨Ô¤ÖõãλÖÃ
|
||||
params = self.ptz.create_type('GotoPreset')
|
||||
params.ProfileToken = self.media_profile.token
|
||||
params.PresetToken = presets_token
|
||||
self.ptz.GotoPreset(params)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
def zoom(self, zoom: str, timeout: int = 1):
|
||||
"""
|
||||
±ä½¹
|
||||
:param zoom: 1ΪÀ½ü»ò-1ΪԶÀë
|
||||
:param timeout: ÉúЧʱ¼ä
|
||||
:return:
|
||||
"""
|
||||
request = self.ptz.create_type('ContinuousMove')
|
||||
request.ProfileToken = self.media_profile.token
|
||||
request.Velocity = {"Zoom": zoom}
|
||||
self.ptz.ContinuousMove(request)
|
||||
time.sleep(timeout)
|
||||
self.ptz.Stop({'ProfileToken': request.ProfileToken})
|
||||
|
||||
def get_status(self):
|
||||
"""
|
||||
»ñÈ¡µ±Ç°Ô¤ÖõãµÄÐÅÏ¢
|
||||
:return:
|
||||
"""
|
||||
params = self.ptz.create_type('GetStatus')
|
||||
params.ProfileToken = self.media_profile.token
|
||||
res = self.ptz.GetStatus(params)
|
||||
print(res.MoveStatus.PanTilt)
|
||||
return res
|
||||
|
||||
def absolute_move(self,p=180,t=0,z=0):
|
||||
pan = p/180.0#0.988889 #- left + right
|
||||
pan_speed = 1
|
||||
tilt = 0.618182 - t/55.0 #+up -down 0~1
|
||||
tilt_speed = 1
|
||||
zoom = 1-z
|
||||
zoom_speed = 1
|
||||
|
||||
# Create media service object
|
||||
# Get target profile
|
||||
request = self.ptz.create_type('AbsoluteMove')
|
||||
request.ProfileToken = self.media_profile.token
|
||||
self.ptz.Stop({'ProfileToken': self.media_profile.token})
|
||||
if request.Position is None:
|
||||
request.Position = self.ptz.GetStatus({'ProfileToken': self.media_profile.token}).Position
|
||||
if request.Speed is None:
|
||||
request.Speed = self.ptz.GetStatus({'ProfileToken': self.media_profile.token}).Position
|
||||
request.Position.PanTilt.x = pan
|
||||
request.Speed.PanTilt.x = pan_speed
|
||||
request.Position.PanTilt.y = tilt
|
||||
request.Speed.PanTilt.y = tilt_speed
|
||||
request.Position.Zoom = zoom
|
||||
request.Speed.Zoom = zoom_speed
|
||||
self.ptz.AbsoluteMove(request)
|
||||
print('finish')
|
||||
|
||||
def deal (p,t,z,o,cap,num,Detection,Fine,img,start):
|
||||
print(p, " ", t, " ", z)
|
||||
o.absolute_move(p, t, z)
|
||||
#time.sleep(1)
|
||||
label = []
|
||||
errorNum = 0
|
||||
while (o.get_status().MoveStatus.PanTilt != "IDLE"):
|
||||
print("camera is moving")
|
||||
if start:
|
||||
time.sleep(5)
|
||||
while True:
|
||||
cap = cv2.VideoCapture("rtsp://admin:whc123456@192.0.0.30:554/h264/ch1/main/av_stream")
|
||||
if cap.isOpened():
|
||||
#time.sleep(1)
|
||||
|
||||
# allcount = cap.get(cv2.CAP_PROP_FRAME_COUNT)
|
||||
# cap.set(cv2.CAP_PROP_POS_FRAMES,allcount)
|
||||
res, frame = cap.read()
|
||||
#a = cap.get(cv2.CAP_PROP_BUFFERSIZE)
|
||||
|
||||
# print(allcount)
|
||||
# while not res:
|
||||
# res, frame = cap.read()
|
||||
if res:
|
||||
|
||||
img_show, label,box = Detection.inference(frame, Fine)
|
||||
img_show = cv2.resize(img_show,(1024,768))
|
||||
# cv2.imshow("AI-ECO",img_show)
|
||||
# cv2.waitKey(1)
|
||||
img.append( Image.fromarray(cv2.cvtColor(img_show, cv2.COLOR_BGR2RGB)))
|
||||
#cv2.imwrite("./test/{}_{}.jpg".format(str(j).zfill(2), str(i).zfill(2)), img_show)
|
||||
num += 1
|
||||
break
|
||||
else:
|
||||
print("empty")
|
||||
errorNum+=1
|
||||
if errorNum>=2:
|
||||
cap = cv2.VideoCapture("rtsp://admin:whc123456@192.0.0.30:554/h264/ch1/main/av_stream")
|
||||
|
||||
return num,img,label,box
|
||||
def long_pic_paste(image):
|
||||
image_result = Image.new(image[0][0].mode, ( 1024 * lieshu,hangshu * 768), 0xffffff)
|
||||
for j in range(hangshu):
|
||||
for i in range(lieshu):
|
||||
#print(j," ",i)
|
||||
image_result.paste(image[j][i], (i*1024, j*768))
|
||||
image_result.save("../data_MPKFNet/result/{}.jpg".format(record_time))
|
||||
if __name__ == '__main__':
|
||||
|
||||
|
||||
o = Onvif_hik(ip="117.178.217.84", username="admin", password="Aa123456")
|
||||
o.absolute_move(1, 0.5, 0.5)
|
||||
Reference in new issue
Block a user