UPDATE Vision 更新行人检测方法
This commit is contained in:
@ -11,6 +11,7 @@ import random
|
||||
import cv2
|
||||
import numpy as np
|
||||
import torch
|
||||
from Vision.tool.CameraHIK import camera_HIK
|
||||
from ultralytics.nn.autobackend import AutoBackend
|
||||
from ultralytics.utils import ops
|
||||
|
||||
@ -23,6 +24,11 @@ class DetectionPerson:
|
||||
"""
|
||||
def __init__(self) -> None:
|
||||
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.cuda = 'cpu'
|
||||
self.conf = 0.40
|
||||
@ -36,30 +42,33 @@ class DetectionPerson:
|
||||
{self.names[i]: (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
|
||||
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
|
||||
# img_src = cv2.imread(img_path)
|
||||
img = self.precess_image(img_src, self.imgsz, self.half, self.cuda)
|
||||
preds = self.model(img)
|
||||
det = ops.non_max_suppression(preds, self.conf, self.iou, classes=None, agnostic=False, max_det=300,
|
||||
nc=len(self.names))
|
||||
if ret:
|
||||
# img_src = cv2.imread(img_path)
|
||||
img = self.precess_image(img_src, self.imgsz, self.half, self.cuda)
|
||||
preds = self.model(img)
|
||||
det = ops.non_max_suppression(preds, self.conf, self.iou, classes=None, agnostic=False, max_det=300,
|
||||
nc=len(self.names))
|
||||
|
||||
for i, pred in enumerate(det):
|
||||
lw = max(round(sum(img_src.shape) / 2 * 0.003), 2) # line width
|
||||
tf = max(lw - 1, 1) # font thickness
|
||||
sf = lw / 3 # font scale
|
||||
pred[:, :4] = ops.scale_boxes(img.shape[2:], pred[:, :4], img_src.shape)
|
||||
results = pred.cpu().detach().numpy()
|
||||
# cv2.imshow('img2', img_src)
|
||||
# cv2.waitKey(1)
|
||||
for result in results:
|
||||
if self.names[result[5]]=="person":
|
||||
person = True
|
||||
conf = round(result[4], 2)
|
||||
print(conf)
|
||||
self.draw_box(img_src, result[:4], conf, self.names[result[5]], lw, sf, tf)
|
||||
for i, pred in enumerate(det):
|
||||
lw = max(round(sum(img_src.shape) / 2 * 0.003), 2) # line width
|
||||
tf = max(lw - 1, 1) # font thickness
|
||||
sf = lw / 3 # font scale
|
||||
pred[:, :4] = ops.scale_boxes(img.shape[2:], pred[:, :4], img_src.shape)
|
||||
results = pred.cpu().detach().numpy()
|
||||
# cv2.imshow('img2', img_src)
|
||||
# cv2.waitKey(1)
|
||||
for result in results:
|
||||
if self.names[result[5]]=="person":
|
||||
person = True
|
||||
conf = round(result[4], 2)
|
||||
#print(conf)
|
||||
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):
|
||||
color = self.color[cls_name]
|
||||
|
||||
Reference in New Issue
Block a user