UPDATE Vision 更新模型

This commit is contained in:
HJW
2024-12-02 15:51:32 +08:00
parent 157e7edce5
commit e2821f7e48
9 changed files with 1228822 additions and 20 deletions

View File

@ -26,7 +26,7 @@ import os
class Detection:
def __init__(self, use_openvino_model=False, cameraType = 'RVC'): # cameraType = 'RVC' or cameraType = 'Pe'
def __init__(self, use_openvino_model=False, cameraType = 'Pe'): # cameraType = 'RVC' or cameraType = 'Pe'
"""
初始化相机及模型
:param use_openvino_model: 选择模型默认使用openvino
@ -36,14 +36,14 @@ class Detection:
self.use_openvino_model = use_openvino_model
self.cameraType = cameraType
if self.use_openvino_model == False:
model_path = ''.join([os.getcwd(), '/Vision/model/pt/best.pt'])
model_path = ''.join([os.getcwd(), '/Vision/model/pt/one_bag.pt'])
device = 'cpu'
if self.cameraType == 'RVC':
self.camera_rvc = camera_rvc()
self.seg_distance_threshold = 0.01 # 1厘米
self.seg_distance_threshold = 10 # 1厘米
elif self.cameraType == 'Pe':
self.camera_rvc = camera_pe()
self.seg_distance_threshold = 20 # 2厘米
self.seg_distance_threshold = 10 # 2厘米
else:
print('相机参数错误')
return
@ -54,7 +54,7 @@ class Detection:
device = 'CPU'
if self.cameraType == 'RVC':
self.camera_rvc = camera_rvc()
self.seg_distance_threshold = 0.01
self.seg_distance_threshold = 10
elif self.cameraType == 'Pe':
self.camera_rvc = camera_pe()
self.seg_distance_threshold = 20
@ -64,7 +64,7 @@ class Detection:
self.model = yolov8_segment_openvino(model_path, device, conf_thres=0.3, iou_thres=0.3)
def get_position(self, Point_isVision=False, Box_isPoint=True, First_Depth =True, Iter_Max_Pixel = 30, save_img_point=0, Height_reduce = 30, width_reduce = 30):
def get_position(self, Point_isVision=False, Box_isPoint=True, First_Depth =True, Iter_Max_Pixel = 30, save_img_point=0, Height_reduce = 50, width_reduce = 50):
"""
检测料袋相关信息
:param Point_isVision: 点云可视化
@ -75,7 +75,7 @@ class Detection:
:param Height_reduce: 检测框的高内缩像素
:param width_reduce: 检测框的宽内缩像素
:return ret: bool 相机是否正常工作
:return img: ndarry 返回img
:return img: ndarray 返回img
:return xyz: list 目标中心点云值形如[x,y,z]
:return nx_ny_nz: list 拟合平面法向量,形如[a,b,c]
:return box_list: list 内缩检测框四顶点,形如[[x1,y1],[],[],[]]

View File

@ -30,7 +30,7 @@ class Detection:
self.use_openvino_model = use_openvino_model
self.cameraType = cameraType
if self.use_openvino_model == False:
model_path = ''.join([os.getcwd(), '/Vision/model/pt/best.pt'])
model_path = ''.join([os.getcwd(), '/Vision/model/pt/one_bag.pt'])
device = 'cpu'
self.model = yolov8_segment()
self.model.load_model(model_path, device)
@ -39,14 +39,14 @@ class Detection:
device = 'CPU'
self.model = yolov8_segment_openvino(model_path, device, conf_thres=0.3, iou_thres=0.3)
img_path = ''.join([os.getcwd(), '/Vision/model/data/test0911.png'])
point_path = ''.join([os.getcwd(), '/Vision/model/data/test0911.xyz'])
img_path = ''.join([os.getcwd(), '/Vision/model/data/2024_11_29_10_05_58.png'])
point_path = ''.join([os.getcwd(), '/Vision/model/data/2024_11_29_10_05_58.xyz'])
self.img = cv2.imread(img_path)
self.point = np.loadtxt(point_path).reshape((1080, 1440, 3))
self.point = np.loadtxt(point_path).reshape((self.img.shape[0], self.img.shape[1], 3))
pass
def get_position(self, Point_isVision=False, Box_isPoint=False, First_Depth =True, Iter_Max_Pixel = 30, save_img_point=0, seg_distance_threshold = 0.01, Height_reduce = 30, width_reduce = 30):
def get_position(self, Point_isVision=False, Box_isPoint=True, First_Depth =True, Iter_Max_Pixel = 30, save_img_point=0, seg_distance_threshold = 10, Height_reduce = 50, width_reduce = 50):
"""
检测料袋相关信息
:param Point_isVision: 点云可视化
@ -167,7 +167,7 @@ class Detection:
'''
rect = cv2.minAreaRect(max_contour)
if rect[1][0] - width_reduce < 30 or rect[1][1] - Height_reduce < 30:
if rect[1][0] - width_reduce > 30 and rect[1][1] - Height_reduce > 30:
rect_reduce = (
(rect[0][0], rect[0][1]), (rect[1][0] - width_reduce, rect[1][1] - Height_reduce), rect[2])
else:

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
# @Time : 2024/9/25 11:47
# @Author : hjw
@ -23,7 +24,7 @@ class DetectionPerson:
:return: person [bool], img [ndarray]
"""
def __init__(self) -> None:
model_path = ''.join([os.getcwd(), '/Vision/model/pt/person.pt'])
model_path = ''.join([os.getcwd(), '/Vision/model/pt/person_detect.pt'])
ip = "192.168.1.65"
port = 554
name = "admin"
@ -61,10 +62,10 @@ class DetectionPerson:
# cv2.imshow('img2', img_src)
# cv2.waitKey(1)
for result in results:
if self.names[result[5]]=="person":
if self.names[result[5]] == "person":
person = True
conf = round(result[4], 2)
#print(conf)
# print(conf)
self.draw_box(img_src, result[:4], conf, self.names[result[5]], lw, sf, tf)
return person, img_src

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

File diff suppressed because it is too large Load Diff

BIN
Vision/model/pt/one_bag.pt Normal file

Binary file not shown.

Binary file not shown.

View File

@ -330,7 +330,7 @@ class yolov8_segment():
preds = result[0]
proto = result[1][-1]
# NMS
det = non_max_suppression(preds, conf_thres=0.25, iou_thres=0.3, nc=len(self.model.CLASSES))[0]
det = non_max_suppression(preds, conf_thres=0.4, iou_thres=0.4, nc=len(self.model.CLASSES))[0]
if det.shape[0] != 0:
# bbox还原至原图尺寸
det[:, :4] = scale_boxes(img.shape[2:], det[:, :4], ori_img.shape)