Merge remote-tracking branch 'origin/master'
This commit is contained in:
@ -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,25 +36,25 @@ 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
|
||||
self.model = yolov8_segment()
|
||||
self.model.load_model(model_path, device)
|
||||
else:
|
||||
model_path = ''.join([os.getcwd(), '/Vision/model/openvino/best.xml'])
|
||||
model_path = ''.join([os.getcwd(), '/Vision/model/openvino/one_bag.xml'])
|
||||
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],[],[],[]]
|
||||
|
||||
@ -30,23 +30,23 @@ 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)
|
||||
else:
|
||||
model_path = ''.join([os.getcwd(), '/Vision/model/openvino/best.xml'])
|
||||
model_path = ''.join([os.getcwd(), '/Vision/model/openvino/one_bag.xml'])
|
||||
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.6, iou_thres=0.6)
|
||||
|
||||
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:
|
||||
|
||||
@ -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"
|
||||
@ -48,6 +49,7 @@ class DetectionPerson:
|
||||
if ret:
|
||||
# img_src = cv2.imread(img_path)
|
||||
img = self.precess_image(img_src, self.imgsz, self.half, self.cuda)
|
||||
img = img[250:1000, 380:2000]
|
||||
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))
|
||||
@ -61,10 +63,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
|
||||
|
||||
30
Vision/find_img_point.py
Normal file
30
Vision/find_img_point.py
Normal file
@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
# @Time : 2024/12/2 15:55
|
||||
# @Author : hjw
|
||||
# @File : find_img_point.py
|
||||
'''
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
img = cv2.imread('./model/data/0925_01_28.png')
|
||||
img2 = img[:600, 380:]
|
||||
cv2.imshow('img2',img2)
|
||||
cv2.imshow('img',img)
|
||||
cv2.waitKey(0)
|
||||
|
||||
def on_EVENT_LBUTTONDOWN(event, x, y, flags, param):
|
||||
if event == cv2.EVENT_LBUTTONDOWN:
|
||||
xy = "%d,%d" % (x, y)
|
||||
cv2.circle(img, (x, y), 1, (255, 0, 0), thickness = -1)
|
||||
cv2.putText(img, xy, (x, y), cv2.FONT_HERSHEY_PLAIN,
|
||||
1.0, (0,0,0), thickness = 1)
|
||||
cv2.imshow("image", img)
|
||||
cv2.namedWindow("image")
|
||||
cv2.setMouseCallback("image", on_EVENT_LBUTTONDOWN)
|
||||
while(1):
|
||||
cv2.imshow("image", img)
|
||||
if cv2.waitKey(0)&0xFF==27:
|
||||
break
|
||||
cv2.destroyAllWindows()
|
||||
BIN
Vision/model/data/0925_01_28.png
Normal file
BIN
Vision/model/data/0925_01_28.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.9 MiB |
BIN
Vision/model/data/2024_11_29_10_05_58.png
Normal file
BIN
Vision/model/data/2024_11_29_10_05_58.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 MiB |
1228800
Vision/model/data/2024_11_29_10_05_58.xyz
Normal file
1228800
Vision/model/data/2024_11_29_10_05_58.xyz
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
description: Ultralytics YOLOv8n-seg model trained on D:\work\ultralytics-main\ultralytics\cfg\datasets\coco8-seg-dy.yaml
|
||||
author: Ultralytics
|
||||
date: '2024-09-10T13:48:59.901222'
|
||||
date: '2024-12-02T17:16:53.470305'
|
||||
version: 8.2.86
|
||||
license: AGPL-3.0 License (https://ultralytics.com/license)
|
||||
docs: https://docs.ultralytics.com
|
||||
@ -11,4 +11,5 @@ imgsz:
|
||||
- 640
|
||||
- 640
|
||||
names:
|
||||
0: box
|
||||
0: zheng
|
||||
1: fan
|
||||
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
BIN
Vision/model/pt/one_bag.pt
Normal file
BIN
Vision/model/pt/one_bag.pt
Normal file
Binary file not shown.
BIN
Vision/model/pt/person_detect.pt
Normal file
BIN
Vision/model/pt/person_detect.pt
Normal file
Binary file not shown.
@ -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)
|
||||
|
||||
@ -22,10 +22,11 @@ import os
|
||||
"""
|
||||
测试 Vision
|
||||
"""
|
||||
|
||||
def detectionPosition_test():
|
||||
detection = Detection()
|
||||
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:
|
||||
print('xyz点云坐标:', xyz)
|
||||
print('nx_ny_nz法向量:', nx_ny_nz)
|
||||
@ -37,7 +38,7 @@ def detectionPosition_test():
|
||||
print("target_position:", target_position)
|
||||
print("noraml_base", noraml_base)
|
||||
cv2.imshow('img', img)
|
||||
cv2.waitKey(1)
|
||||
cv2.waitKey(0)
|
||||
|
||||
def take_photo_position_test():
|
||||
detection = Detection()
|
||||
@ -113,4 +114,4 @@ def bag_collection_test():
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
bag_collection_test()
|
||||
detectionPosition_test()
|
||||
Reference in New Issue
Block a user