UPDATE Vision 更新行人检测方法
This commit is contained in:
@ -11,6 +11,7 @@ import random
|
|||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import torch
|
import torch
|
||||||
|
from Vision.tool.CameraHIK import camera_HIK
|
||||||
from ultralytics.nn.autobackend import AutoBackend
|
from ultralytics.nn.autobackend import AutoBackend
|
||||||
from ultralytics.utils import ops
|
from ultralytics.utils import ops
|
||||||
|
|
||||||
@ -23,6 +24,11 @@ class DetectionPerson:
|
|||||||
"""
|
"""
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
model_path = ''.join([os.getcwd(), '/Vision/model/pt/person.pt'])
|
model_path = ''.join([os.getcwd(), '/Vision/model/pt/person.pt'])
|
||||||
|
ip = "192.168.1.65"
|
||||||
|
port = 554
|
||||||
|
name = "admin"
|
||||||
|
pw = "lzhk.159"
|
||||||
|
self.HIk_Camera = camera_HIK(ip, port, name, pw)
|
||||||
self.imgsz = 640
|
self.imgsz = 640
|
||||||
self.cuda = 'cpu'
|
self.cuda = 'cpu'
|
||||||
self.conf = 0.40
|
self.conf = 0.40
|
||||||
@ -36,8 +42,10 @@ class DetectionPerson:
|
|||||||
{self.names[i]: (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
|
{self.names[i]: (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
|
||||||
for i in range(len(self.names))})
|
for i in range(len(self.names))})
|
||||||
|
|
||||||
def get_person(self, img_src):
|
def get_person(self):
|
||||||
|
ret, img_src = self.HIk_Camera.get_img()
|
||||||
person = False
|
person = False
|
||||||
|
if ret:
|
||||||
# img_src = cv2.imread(img_path)
|
# img_src = cv2.imread(img_path)
|
||||||
img = self.precess_image(img_src, self.imgsz, self.half, self.cuda)
|
img = self.precess_image(img_src, self.imgsz, self.half, self.cuda)
|
||||||
preds = self.model(img)
|
preds = self.model(img)
|
||||||
@ -56,10 +64,11 @@ class DetectionPerson:
|
|||||||
if self.names[result[5]]=="person":
|
if self.names[result[5]]=="person":
|
||||||
person = True
|
person = True
|
||||||
conf = round(result[4], 2)
|
conf = round(result[4], 2)
|
||||||
print(conf)
|
#print(conf)
|
||||||
self.draw_box(img_src, result[:4], conf, self.names[result[5]], lw, sf, tf)
|
self.draw_box(img_src, result[:4], conf, self.names[result[5]], lw, sf, tf)
|
||||||
|
|
||||||
return person, img_src
|
return person, img_src
|
||||||
|
return person, None
|
||||||
|
|
||||||
def draw_box(self, img_src, box, conf, cls_name, lw, sf, tf):
|
def draw_box(self, img_src, box, conf, cls_name, lw, sf, tf):
|
||||||
color = self.color[cls_name]
|
color = self.color[cls_name]
|
||||||
|
|||||||
@ -23,14 +23,14 @@ class camera_HIK():
|
|||||||
|
|
||||||
def __init__(self, ip, port, name, pw):
|
def __init__(self, ip, port, name, pw):
|
||||||
# "rtsp://admin:zlzk.123@192.168.1.64:554"
|
# "rtsp://admin:zlzk.123@192.168.1.64:554"
|
||||||
self.camera_url = "rtsp://" + name + ":" + pw + "@" + ip + ":" + str(port)
|
|
||||||
ret = portisopen(ip, port)
|
ret = portisopen(ip, port)
|
||||||
|
self.camera_url = "rtsp://" + str(name) + ":" + str(pw) + "@" + str(ip) + ":" + str(port)
|
||||||
self.ip = ip
|
self.ip = ip
|
||||||
self.port = port
|
self.port = port
|
||||||
self.init_success = False
|
self.init_success = False
|
||||||
if ret:
|
if ret:
|
||||||
self.cap = cv2.VideoCapture(self.camera_url)
|
self.cap = cv2.VideoCapture(self.camera_url)
|
||||||
self.init_sucess = True
|
self.init_success = True
|
||||||
else:
|
else:
|
||||||
print('海康摄像头网络错误,请检测IP')
|
print('海康摄像头网络错误,请检测IP')
|
||||||
|
|
||||||
|
|||||||
@ -51,17 +51,23 @@ def take_photo_position_test():
|
|||||||
|
|
||||||
def detectionPerson_test():
|
def detectionPerson_test():
|
||||||
detectionPerson = DetectionPerson()
|
detectionPerson = DetectionPerson()
|
||||||
video_path = ''.join([os.getcwd(), '/Vision/model/data/1.mp4'])
|
while True:
|
||||||
cam = cv2.VideoCapture(video_path)
|
person, img_src = detectionPerson.get_person()
|
||||||
while cam.isOpened():
|
if img_src is not None:
|
||||||
ret, frame = cam.read()
|
cv2.imshow('detectPerson', img_src)
|
||||||
if ret:
|
|
||||||
person, img = detectionPerson.get_person(frame)
|
|
||||||
print(person)
|
|
||||||
cv2.imshow('img', img)
|
|
||||||
cv2.waitKey(1)
|
cv2.waitKey(1)
|
||||||
else:
|
print("person", person)
|
||||||
break
|
# video_path = ''.join([os.getcwd(), '/Vision/model/data/1.mp4'])
|
||||||
|
# cam = cv2.VideoCapture(video_path)
|
||||||
|
# while cam.isOpened():
|
||||||
|
# ret, frame = cam.read()
|
||||||
|
# if ret:
|
||||||
|
# person, img = detectionPerson.get_person(frame)
|
||||||
|
# print(person)
|
||||||
|
# cv2.imshow('img', img)
|
||||||
|
# cv2.waitKey(1)
|
||||||
|
# else:
|
||||||
|
# break
|
||||||
|
|
||||||
def HIK_Camera_test():
|
def HIK_Camera_test():
|
||||||
MY_CAMERA = camera_HIK("192.168.1.121", 554, "admin", "zlzk.123")
|
MY_CAMERA = camera_HIK("192.168.1.121", 554, "admin", "zlzk.123")
|
||||||
@ -87,4 +93,4 @@ def detectionBagNum_test():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
detectionBagNum_test()
|
detectionPerson_test()
|
||||||
Reference in New Issue
Block a user