UPDATE Vision box:点云与相机坐标

This commit is contained in:
HJW
2024-10-09 17:34:39 +08:00
parent 1feb28b68d
commit 25bb85dca1
3 changed files with 89 additions and 8 deletions

View File

@ -21,6 +21,7 @@ from Vision.tool.utils import class_names
from Vision.tool.utils import get_disk_space
from Vision.tool.utils import remove_nan_mean_value
from Vision.tool.utils import out_bounds_dete
from Vision.tool.utils import uv_to_XY
import os
class Detection:
@ -45,7 +46,7 @@ class Detection:
pass
def get_position(self, Point_isVision=False, Box_isPoint=True, save_img_point=0, seg_distance_threshold = 0.01, Height_reduce = 30, width_reduce = 30):
def get_position(self, Point_isVision=False, Box_isPoint=False, save_img_point=0, seg_distance_threshold = 0.01, Height_reduce = 30, width_reduce = 30):
"""
检测料袋相关信息
:param Point_isVision: 点云可视化
@ -209,8 +210,8 @@ class Detection:
ransac_n=5,
num_iterations=5000)
[a, b, c, d] = plane_model
# print(f"Plane equation: {a:.2f}x + {b:.2f}y + {c:.2f}z + {d:.2f} = 0")
# print(f"Plane equation: {a:.2f}x + {b:.2f}y + {c:.2f}z + {d:.2f} = 0")
# inlier_cloud = pcd.select_by_index(inliers) # 点云可视化
# inlier_cloud.paint_uniform_color([1.0, 0, 0])
# outlier_cloud = pcd.select_by_index(inliers, invert=True)
@ -230,7 +231,10 @@ class Detection:
box_point_x3, box_point_y3, box_point_z3 = remove_nan_mean_value(pm, box[2][0][1], box[2][0][0])
box_point_x4, box_point_y4, box_point_z4 = remove_nan_mean_value(pm, box[3][0][1], box[3][0][0])
else:
pass
x1, y1, z1 = uv_to_XY(self.cameraType, box[0][0][0], box[0][0][1])
x2, y2, z2 = uv_to_XY(self.cameraType, box[1][0][0], box[1][0][1])
x3, y3, z3 = uv_to_XY(self.cameraType, box[2][0][0], box[2][0][1])
x4, y4, z4 = uv_to_XY(self.cameraType, box[3][0][0], box[3][0][1])
x_rotation_center = int((box[0][0][0] + box[1][0][0] + box[2][0][0] + box[3][0][0]) / 4)
y_rotation_center = int((box[0][0][1] + box[1][0][1] + box[2][0][1] + box[3][0][1]) / 4)
point_x, point_y, point_z = remove_nan_mean_value(pm, y_rotation_center, x_rotation_center)
@ -245,8 +249,18 @@ class Detection:
[box_point_x3, box_point_y3, box_point_z3],
[box_point_x4, box_point_y4, box_point_z4]])
else:
box_list.append(box)
Depth_Z.append(point_z * 1000)
box_list.append([[x1, y1, z1],
[x2, y2, z2],
[x3, y3, z3],
[x4, y4, z4],
])
if self.cameraType == 'RVC':
xyz.append([point_x * 1000, point_y * 1000, point_z * 1000])
Depth_Z.append(point_z * 1000)
elif self.cameraType == 'Pe':
xyz.append([point_x, point_y, point_z])
Depth_Z.append(point_z)
#Depth_Z.append(point_z * 1000)
nx_ny_nz.append([a, b, c])
RegionalArea.append(cv2.contourArea(max_contour))
uv.append([x_rotation_center, y_rotation_center])