UPDATE openvino
This commit is contained in:
@ -15,29 +15,24 @@ from Vision.tool.CameraRVC import camera
|
|||||||
from Vision.yolo.yolov8_pt_seg import yolov8_segment
|
from Vision.yolo.yolov8_pt_seg import yolov8_segment
|
||||||
from Vision.yolo.yolov8_openvino import yolov8_segment_openvino
|
from Vision.yolo.yolov8_openvino import yolov8_segment_openvino
|
||||||
from Vision.tool.utils import find_position
|
from Vision.tool.utils import find_position
|
||||||
from Vision.tool.utils import class_names
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
class Detection:
|
class Detection:
|
||||||
|
|
||||||
def __init__(self, use_openvino_model = False):
|
def __init__(self, use_openvino_model = False):
|
||||||
print(os.getcwd())
|
|
||||||
self.use_openvino_model = use_openvino_model
|
self.use_openvino_model = use_openvino_model
|
||||||
if self.use_openvino_model==False:
|
if self.use_openvino_model==False:
|
||||||
model_path = ''.join([os.getcwd(), '/model/pt/best.pt'])
|
model_path = ''.join([os.getcwd(), '/model/pt/best.pt'])
|
||||||
device = 'cpu'
|
device = 'cpu'
|
||||||
|
self.camera_rvc = camera()
|
||||||
self.model = yolov8_segment()
|
self.model = yolov8_segment()
|
||||||
self.model.load_model(model_path, device)
|
self.model.load_model(model_path, device)
|
||||||
else:
|
else:
|
||||||
model_path = ''.join([os.getcwd(), '/model/openvino/bset.xml'])
|
model_path = ''.join([os.getcwd(), '/model/openvino/last-0903.xml'])
|
||||||
device = 'CPU'
|
device = 'CPU'
|
||||||
|
self.camera_rvc = camera()
|
||||||
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(), '/model/data/test0910.png'])
|
|
||||||
point_path = ''.join([os.getcwd(), '/model/data/test0910.xyz'])
|
|
||||||
self.img = cv2.imread(img_path)
|
|
||||||
self.point = np.loadtxt(point_path).reshape((1080, 1440, 3))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_position(self, Point_isVision=True):
|
def get_position(self, Point_isVision=True):
|
||||||
@ -46,16 +41,13 @@ class Detection:
|
|||||||
:param api: None
|
:param api: None
|
||||||
:return: ret , img, (x,y,z), (nx, ny, nz)
|
:return: ret , img, (x,y,z), (nx, ny, nz)
|
||||||
'''
|
'''
|
||||||
#ret, img, pm = self.camera_rvc.get_img_and_point_map() # 拍照,获取图像及
|
ret, img, pm = self.camera_rvc.get_img_and_point_map() # 拍照,获取图像及
|
||||||
ret = 1
|
if self.camera_rvc.caminit_isok == True:
|
||||||
img = self.img
|
|
||||||
pm = self.point
|
|
||||||
if ret == 1:
|
if ret == 1:
|
||||||
if self.use_openvino_model == False:
|
if self.use_openvino_model == False:
|
||||||
flag, det_cpu, dst_img, masks, category_names = self.model.model_inference(img, 0)
|
flag, det_cpu, dst_img, masks, category_names = self.model.model_inference(img, 0)
|
||||||
else:
|
else:
|
||||||
flag, det_cpu, scores, masks, category_names = self.model.segment_objects(img)
|
flag, det_cpu, scores, masks, category_names = self.model.segment_objects(img)
|
||||||
dst_img = img
|
|
||||||
if flag == 1:
|
if flag == 1:
|
||||||
xyz = []
|
xyz = []
|
||||||
nx_ny_nz = []
|
nx_ny_nz = []
|
||||||
@ -76,10 +68,7 @@ class Detection:
|
|||||||
|
|
||||||
# 画box
|
# 画box
|
||||||
box_x1, box_y1, box_x2, box_y2 = item[0:4].astype(np.int32)
|
box_x1, box_y1, box_x2, box_y2 = item[0:4].astype(np.int32)
|
||||||
if self.use_openvino_model == False:
|
|
||||||
label = category_names[int(item[5])]
|
label = category_names[int(item[5])]
|
||||||
else:
|
|
||||||
label = class_names[int(item[4])]
|
|
||||||
rand_color = (0, 255, 255)
|
rand_color = (0, 255, 255)
|
||||||
score = item[4]
|
score = item[4]
|
||||||
org = (int((box_x1 + box_x2) / 2), int((box_y1 + box_y2) / 2))
|
org = (int((box_x1 + box_x2) / 2), int((box_y1 + box_y2) / 2))
|
||||||
@ -133,6 +122,10 @@ class Detection:
|
|||||||
select_point = np.array(select_point)
|
select_point = np.array(select_point)
|
||||||
pm_seg = select_point.reshape(-1, 3)
|
pm_seg = select_point.reshape(-1, 3)
|
||||||
pm_seg = pm_seg[~np.isnan(pm_seg).all(axis=-1), :] # 剔除 nan
|
pm_seg = pm_seg[~np.isnan(pm_seg).all(axis=-1), :] # 剔除 nan
|
||||||
|
if pm_seg.size<300:
|
||||||
|
print("分割点云数量较少,无法拟合平面")
|
||||||
|
continue
|
||||||
|
|
||||||
# cv2.imshow('result', piont_result)
|
# cv2.imshow('result', piont_result)
|
||||||
|
|
||||||
'''
|
'''
|
||||||
@ -186,7 +179,7 @@ class Detection:
|
|||||||
if _idx == None:
|
if _idx == None:
|
||||||
return 1, img, None, None
|
return 1, img, None, None
|
||||||
else:
|
else:
|
||||||
cv2.circle(img, (uv[_idx][0], uv[_idx][1]), 30, (0, 0, 255), 20) # 标出中心点
|
cv2.circle(img, (uv[_idx][0], uv[_idx][1]), 30, (255, 0, 0), 20) # 标出中心点
|
||||||
|
|
||||||
if Point_isVision==True:
|
if Point_isVision==True:
|
||||||
pcd = o3d.geometry.PointCloud()
|
pcd = o3d.geometry.PointCloud()
|
||||||
@ -208,7 +201,12 @@ class Detection:
|
|||||||
print("RVC X Camera capture failed!")
|
print("RVC X Camera capture failed!")
|
||||||
return 0, None, None, None
|
return 0, None, None, None
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("RVC X Camera is not opened!")
|
||||||
|
return 0, None, None, None
|
||||||
|
|
||||||
def release(self):
|
def release(self):
|
||||||
|
self.camera_rvc.release()
|
||||||
self.model.clear()
|
self.model.clear()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -54,7 +54,6 @@ class Detection:
|
|||||||
flag, det_cpu, dst_img, masks, category_names = self.model.model_inference(img, 0)
|
flag, det_cpu, dst_img, masks, category_names = self.model.model_inference(img, 0)
|
||||||
else:
|
else:
|
||||||
flag, det_cpu, scores, masks, category_names = self.model.segment_objects(img)
|
flag, det_cpu, scores, masks, category_names = self.model.segment_objects(img)
|
||||||
dst_img = img
|
|
||||||
if flag == 1:
|
if flag == 1:
|
||||||
xyz = []
|
xyz = []
|
||||||
nx_ny_nz = []
|
nx_ny_nz = []
|
||||||
@ -132,6 +131,9 @@ class Detection:
|
|||||||
select_point = np.array(select_point)
|
select_point = np.array(select_point)
|
||||||
pm_seg = select_point.reshape(-1, 3)
|
pm_seg = select_point.reshape(-1, 3)
|
||||||
pm_seg = pm_seg[~np.isnan(pm_seg).all(axis=-1), :] # 剔除 nan
|
pm_seg = pm_seg[~np.isnan(pm_seg).all(axis=-1), :] # 剔除 nan
|
||||||
|
if pm_seg.size < 300:
|
||||||
|
print("分割点云数量较少,无法拟合平面")
|
||||||
|
continue
|
||||||
# cv2.imshow('result', piont_result)
|
# cv2.imshow('result', piont_result)
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|||||||
Reference in New Issue
Block a user