UPDATE Vision 图漾相机代码融合
This commit is contained in:
@ -11,8 +11,8 @@
|
||||
import numpy as np
|
||||
import cv2
|
||||
import open3d as o3d
|
||||
# from Vision.tool.CameraRVC import camera
|
||||
from Vision.tool.CameraPe import camera
|
||||
from Vision.tool.CameraRVC import camera_rvc
|
||||
from Vision.tool.CameraPe import camera_pe
|
||||
from Vision.yolo.yolov8_pt_seg import yolov8_segment
|
||||
from Vision.yolo.yolov8_openvino import yolov8_segment_openvino
|
||||
from Vision.tool.utils import find_position
|
||||
@ -25,23 +25,33 @@ import os
|
||||
|
||||
class Detection:
|
||||
|
||||
def __init__(self, use_openvino_model=True):
|
||||
def __init__(self, use_openvino_model=True, cameraIsRVC = True):
|
||||
self.use_openvino_model = use_openvino_model
|
||||
if self.use_openvino_model==False:
|
||||
model_path = ''.join([os.getcwd(), '/Vision/model/pt/best.pt'])
|
||||
device = 'cpu'
|
||||
self.camera_rvc = camera()
|
||||
if cameraIsRVC == True:
|
||||
self.camera_rvc = camera_rvc()
|
||||
self.seg_distance_threshold = 0.005
|
||||
else:
|
||||
self.camera_rvc = camera_pe()
|
||||
self.seg_distance_threshold = 10
|
||||
self.model = yolov8_segment()
|
||||
self.model.load_model(model_path, device)
|
||||
else:
|
||||
model_path = ''.join([os.getcwd(), '/Vision/model/openvino/best.xml'])
|
||||
device = 'CPU'
|
||||
self.camera_rvc = camera()
|
||||
if cameraIsRVC == True:
|
||||
self.camera_rvc = camera_rvc()
|
||||
self.seg_distance_threshold = 0.005
|
||||
else:
|
||||
self.camera_rvc = camera_pe()
|
||||
self.seg_distance_threshold = 10
|
||||
self.model = yolov8_segment_openvino(model_path, device, conf_thres=0.3, iou_thres=0.3)
|
||||
|
||||
|
||||
|
||||
def get_position(self, Point_isVision=False, save_img_point=False, seg_distance_threshold= 10):
|
||||
def get_position(self, Point_isVision=False, save_img_point=False):
|
||||
""
|
||||
'''
|
||||
:param api: None
|
||||
@ -158,7 +168,7 @@ class Detection:
|
||||
'''
|
||||
pcd = o3d.geometry.PointCloud()
|
||||
pcd.points = o3d.utility.Vector3dVector(pm_seg)
|
||||
plane_model, inliers = pcd.segment_plane(distance_threshold=seg_distance_threshold,
|
||||
plane_model, inliers = pcd.segment_plane(distance_threshold=self.seg_distance_threshold,
|
||||
ransac_n=5,
|
||||
num_iterations=5000)
|
||||
[a, b, c, d] = plane_model
|
||||
@ -223,7 +233,7 @@ class Detection:
|
||||
if Point_isVision==True:
|
||||
pcd = o3d.geometry.PointCloud()
|
||||
pcd.points = o3d.utility.Vector3dVector(seg_point[_idx])
|
||||
plane_model, inliers = pcd.segment_plane(distance_threshold=seg_distance_threshold,
|
||||
plane_model, inliers = pcd.segment_plane(distance_threshold=self.seg_distance_threshold,
|
||||
ransac_n=5,
|
||||
num_iterations=5000)
|
||||
inlier_cloud = pcd.select_by_index(inliers) # 点云可视化
|
||||
|
||||
@ -12,7 +12,8 @@ import numpy as np
|
||||
import cv2
|
||||
import open3d as o3d
|
||||
import time
|
||||
from Vision.tool.CameraRVC import camera
|
||||
from Vision.tool.CameraRVC import camera_rvc
|
||||
from Vision.tool.CameraPe import camera_pe
|
||||
from Vision.yolo.yolov8_pt_seg import yolov8_segment
|
||||
from Vision.yolo.yolov8_openvino import yolov8_segment_openvino
|
||||
from Vision.tool.utils import find_position
|
||||
@ -24,7 +25,7 @@ import os
|
||||
|
||||
class Detection:
|
||||
|
||||
def __init__(self, use_openvino_model = True):
|
||||
def __init__(self, use_openvino_model = True, cameraIsRVC = True):
|
||||
self.use_openvino_model = use_openvino_model
|
||||
if self.use_openvino_model == False:
|
||||
model_path = ''.join([os.getcwd(), '/Vision/model/pt/best.pt'])
|
||||
@ -36,14 +37,15 @@ 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/1.png'])
|
||||
point_path = ''.join([os.getcwd(), '/Vision/model/data/1.xyz'])
|
||||
self.img = cv2.imread(img_path)
|
||||
self.point = np.loadtxt(point_path).reshape((1080, 1440, 3))
|
||||
pass
|
||||
|
||||
|
||||
|
||||
def get_position(self, Point_isVision=False, save_img_point=True, seg_distance_threshold = 10):
|
||||
def get_position(self, Point_isVision=False, save_img_point=True, seg_distance_threshold = 0.01):
|
||||
""
|
||||
'''
|
||||
:param api: None
|
||||
@ -186,8 +188,15 @@ class Detection:
|
||||
|
||||
# 这一步不影响后面的画图,但是可以保证四个角点坐标为顺时针
|
||||
startidx = box.sum(axis=1).argmin()
|
||||
box1 = np.roll(box, 4 - startidx, 0)
|
||||
box = np.roll(box, 4 - startidx, 0)
|
||||
box = np.int0(box)
|
||||
# 在原图上画出预测的外接矩形
|
||||
|
||||
'''
|
||||
拟合最大内接矩形,计算矩形中心
|
||||
'''
|
||||
|
||||
|
||||
box = box.reshape((-1, 1, 2)).astype(np.int32)
|
||||
box = box + [[[box_x1, box_y1]], [[box_x1, box_y1]], [[box_x1, box_y1]], [[box_x1, box_y1]]]
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ class PythonPercipioDeviceEvent(pcammls.DeviceEvent):
|
||||
def IsOffline(self):
|
||||
return self.Offline
|
||||
|
||||
class camera():
|
||||
class camera_pe():
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
import PyRVC as RVC
|
||||
import numpy as np
|
||||
|
||||
class camera:
|
||||
class camera_rvc:
|
||||
|
||||
def __init__(self):
|
||||
self.caminit_isok = False
|
||||
|
||||
Reference in New Issue
Block a user