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: 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 :param use_openvino_model: 选择模型默认使用openvino
@ -36,14 +36,14 @@ class Detection:
self.use_openvino_model = use_openvino_model self.use_openvino_model = use_openvino_model
self.cameraType = cameraType self.cameraType = cameraType
if self.use_openvino_model == False: 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' device = 'cpu'
if self.cameraType == 'RVC': if self.cameraType == 'RVC':
self.camera_rvc = camera_rvc() self.camera_rvc = camera_rvc()
self.seg_distance_threshold = 0.01 # 1厘米 self.seg_distance_threshold = 10 # 1厘米
elif self.cameraType == 'Pe': elif self.cameraType == 'Pe':
self.camera_rvc = camera_pe() self.camera_rvc = camera_pe()
self.seg_distance_threshold = 20 # 2厘米 self.seg_distance_threshold = 10 # 2厘米
else: else:
print('相机参数错误') print('相机参数错误')
return return
@ -54,7 +54,7 @@ class Detection:
device = 'CPU' device = 'CPU'
if self.cameraType == 'RVC': if self.cameraType == 'RVC':
self.camera_rvc = camera_rvc() self.camera_rvc = camera_rvc()
self.seg_distance_threshold = 0.01 self.seg_distance_threshold = 10
elif self.cameraType == 'Pe': elif self.cameraType == 'Pe':
self.camera_rvc = camera_pe() self.camera_rvc = camera_pe()
self.seg_distance_threshold = 20 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) 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: 点云可视化 :param Point_isVision: 点云可视化
@ -75,7 +75,7 @@ class Detection:
:param Height_reduce: 检测框的高内缩像素 :param Height_reduce: 检测框的高内缩像素
:param width_reduce: 检测框的宽内缩像素 :param width_reduce: 检测框的宽内缩像素
:return ret: bool 相机是否正常工作 :return ret: bool 相机是否正常工作
:return img: ndarry 返回img :return img: ndarray 返回img
:return xyz: list 目标中心点云值形如[x,y,z] :return xyz: list 目标中心点云值形如[x,y,z]
:return nx_ny_nz: list 拟合平面法向量,形如[a,b,c] :return nx_ny_nz: list 拟合平面法向量,形如[a,b,c]
:return box_list: list 内缩检测框四顶点,形如[[x1,y1],[],[],[]] :return box_list: list 内缩检测框四顶点,形如[[x1,y1],[],[],[]]

View File

@ -30,7 +30,7 @@ class Detection:
self.use_openvino_model = use_openvino_model self.use_openvino_model = use_openvino_model
self.cameraType = cameraType self.cameraType = cameraType
if self.use_openvino_model == False: 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' device = 'cpu'
self.model = yolov8_segment() self.model = yolov8_segment()
self.model.load_model(model_path, device) self.model.load_model(model_path, device)
@ -39,14 +39,14 @@ class Detection:
device = 'CPU' device = 'CPU'
self.model = yolov8_segment_openvino(model_path, device, conf_thres=0.3, iou_thres=0.3) 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']) img_path = ''.join([os.getcwd(), '/Vision/model/data/2024_11_29_10_05_58.png'])
point_path = ''.join([os.getcwd(), '/Vision/model/data/test0911.xyz']) point_path = ''.join([os.getcwd(), '/Vision/model/data/2024_11_29_10_05_58.xyz'])
self.img = cv2.imread(img_path) 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 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: 点云可视化 :param Point_isVision: 点云可视化
@ -167,7 +167,7 @@ class Detection:
''' '''
rect = cv2.minAreaRect(max_contour) 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_reduce = (
(rect[0][0], rect[0][1]), (rect[1][0] - width_reduce, rect[1][1] - Height_reduce), rect[2]) (rect[0][0], rect[0][1]), (rect[1][0] - width_reduce, rect[1][1] - Height_reduce), rect[2])
else: else:

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
''' '''
# @Time : 2024/9/25 11:47 # @Time : 2024/9/25 11:47
# @Author : hjw # @Author : hjw
@ -23,7 +24,7 @@ class DetectionPerson:
:return: person [bool], img [ndarray] :return: person [bool], img [ndarray]
""" """
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_detect.pt'])
ip = "192.168.1.65" ip = "192.168.1.65"
port = 554 port = 554
name = "admin" name = "admin"

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] preds = result[0]
proto = result[1][-1] proto = result[1][-1]
# NMS # 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: if det.shape[0] != 0:
# bbox还原至原图尺寸 # bbox还原至原图尺寸
det[:, :4] = scale_boxes(img.shape[2:], det[:, :4], ori_img.shape) det[:, :4] = scale_boxes(img.shape[2:], det[:, :4], ori_img.shape)

View File

@ -22,10 +22,11 @@ import os
""" """
测试 Vision 测试 Vision
""" """
def detectionPosition_test(): def detectionPosition_test():
detection = Detection() detection = Detection()
while True: while True:
ret, img, xyz, nx_ny_nz, box = detection.get_position() ret, img, xyz, nx_ny_nz, box = detection.get_position(Point_isVision=True)
if ret==1: if ret==1:
print('xyz点云坐标', xyz) print('xyz点云坐标', xyz)
print('nx_ny_nz法向量', nx_ny_nz) print('nx_ny_nz法向量', nx_ny_nz)
@ -37,7 +38,7 @@ def detectionPosition_test():
print("target_position:", target_position) print("target_position:", target_position)
print("noraml_base", noraml_base) print("noraml_base", noraml_base)
cv2.imshow('img', img) cv2.imshow('img', img)
cv2.waitKey(1) cv2.waitKey(0)
def take_photo_position_test(): def take_photo_position_test():
detection = Detection() detection = Detection()
@ -113,4 +114,4 @@ def bag_collection_test():
if __name__ == '__main__': if __name__ == '__main__':
bag_collection_test() detectionPosition_test()