UPDATE Vision 更新点云选取逻辑
This commit is contained in:
@ -51,7 +51,7 @@ class Detection:
|
||||
|
||||
|
||||
|
||||
def get_position(self, Point_isVision=False, save_img_point=False):
|
||||
def get_position(self, Point_isVision=False, save_img_point=False, Height_reduce = 30, width_reduce = 30):
|
||||
""
|
||||
'''
|
||||
:param api: None
|
||||
@ -145,11 +145,34 @@ class Detection:
|
||||
if perimeter > max_perimeter:
|
||||
max_perimeter = perimeter
|
||||
max_contour = contour
|
||||
|
||||
'''
|
||||
拟合最小外接矩形,计算矩形中心
|
||||
'''
|
||||
|
||||
rect = cv2.minAreaRect(max_contour)
|
||||
rect_reduce = (
|
||||
(rect[0][0], rect[0][1]), (rect[1][0] - width_reduce, rect[1][1] - Height_reduce), rect[2])
|
||||
# cv2.boxPoints可以将轮廓点转换为四个角点坐标
|
||||
box_outside = cv2.boxPoints(rect)
|
||||
# 这一步不影响后面的画图,但是可以保证四个角点坐标为顺时针
|
||||
startidx = box_outside.sum(axis=1).argmin()
|
||||
box_outside = np.roll(box_outside, 4 - startidx, 0)
|
||||
box_outside = np.intp(box_outside)
|
||||
box_outside = box_outside.reshape((-1, 1, 2)).astype(np.int32)
|
||||
|
||||
# cv2.boxPoints可以将轮廓点转换为四个角点坐标
|
||||
box_reduce = cv2.boxPoints(rect_reduce)
|
||||
startidx = box_reduce.sum(axis=1).argmin()
|
||||
box_reduce = np.roll(box_reduce, 4 - startidx, 0)
|
||||
box_reduce = np.intp(box_reduce)
|
||||
box_reduce = box_reduce.reshape((-1, 1, 2)).astype(np.int32)
|
||||
|
||||
'''
|
||||
提取区域范围内的(x, y)
|
||||
'''
|
||||
mask_inside = np.zeros(binary.shape, np.uint8)
|
||||
cv2.drawContours(mask_inside, [max_contour], 0, 255, -1)
|
||||
cv2.fillPoly(mask_inside, [box_reduce], (255))
|
||||
pixel_point2 = cv2.findNonZero(mask_inside)
|
||||
# result = np.zeros_like(color_image)
|
||||
select_point = []
|
||||
@ -180,19 +203,8 @@ class Detection:
|
||||
# outlier_cloud.paint_uniform_color([0, 1, 0])
|
||||
# o3d.visualization.draw_geometries([inlier_cloud, outlier_cloud])
|
||||
|
||||
'''
|
||||
拟合最小外接矩形,计算矩形中心
|
||||
'''
|
||||
|
||||
rect = cv2.minAreaRect(max_contour)
|
||||
# cv2.boxPoints可以将轮廓点转换为四个角点坐标
|
||||
box = cv2.boxPoints(rect)
|
||||
# 这一步不影响后面的画图,但是可以保证四个角点坐标为顺时针
|
||||
startidx = box.sum(axis=1).argmin()
|
||||
box = np.roll(box, 4 - startidx, 0)
|
||||
# 在原图上画出预测的外接矩形
|
||||
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]]]
|
||||
box_outside = box_outside + [[[box_x1, box_y1]], [[box_x1, box_y1]], [[box_x1, box_y1]],[[box_x1, box_y1]]]
|
||||
box = box_reduce + [[[box_x1, box_y1]], [[box_x1, box_y1]], [[box_x1, box_y1]], [[box_x1, box_y1]]]
|
||||
|
||||
box[0][0][1], box[0][0][0] = out_bounds_dete(pm.shape[0], pm.shape[1], box[0][0][1], box[0][0][0])
|
||||
box[1][0][1], box[1][0][0] = out_bounds_dete(pm.shape[0], pm.shape[1], box[1][0][1], box[1][0][0])
|
||||
@ -222,6 +234,7 @@ class Detection:
|
||||
uv.append([x_rotation_center, y_rotation_center])
|
||||
seg_point.append(pm_seg)
|
||||
cv2.polylines(img, [box], True, (0, 255, 0), 2)
|
||||
cv2.polylines(img, [box_outside], True, (226, 12, 89), 2)
|
||||
|
||||
_idx = find_position(Depth_Z, RegionalArea, 100,True)
|
||||
|
||||
|
||||
@ -37,15 +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/1.png'])
|
||||
point_path = ''.join([os.getcwd(), '/Vision/model/data/1.xyz'])
|
||||
img_path = ''.join([os.getcwd(), '/Vision/model/data/test0911.png'])
|
||||
point_path = ''.join([os.getcwd(), '/Vision/model/data/test0911.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 = 0.01):
|
||||
def get_position(self, Point_isVision=True, save_img_point=True, seg_distance_threshold = 0.01, Height_reduce = 30, width_reduce = 30):
|
||||
""
|
||||
'''
|
||||
:param api: None
|
||||
@ -133,7 +133,7 @@ class Detection:
|
||||
ret, binary = cv2.threshold(imgray, 10, 255, 0)
|
||||
# 阈值 二进制图像
|
||||
# cv2.imshow('bin',binary)
|
||||
# cv2.waitKey(1)
|
||||
# cv2.waitKey(0)
|
||||
contours, hierarchy = cv2.findContours(binary, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
|
||||
# all_point_list = contours_in(contours)
|
||||
# print(len(all_point_list))
|
||||
@ -144,11 +144,35 @@ class Detection:
|
||||
if perimeter > max_perimeter:
|
||||
max_perimeter = perimeter
|
||||
max_contour = contour
|
||||
'''
|
||||
拟合最小外接矩形,计算矩形中心
|
||||
'''
|
||||
|
||||
rect = cv2.minAreaRect(max_contour)
|
||||
rect_reduce = ((rect[0][0], rect[0][1]), (rect[1][0] - width_reduce, rect[1][1] - Height_reduce), rect[2])
|
||||
# cv2.boxPoints可以将轮廓点转换为四个角点坐标
|
||||
box_outside = cv2.boxPoints(rect)
|
||||
# 这一步不影响后面的画图,但是可以保证四个角点坐标为顺时针
|
||||
startidx = box_outside.sum(axis=1).argmin()
|
||||
box_outside = np.roll(box_outside, 4 - startidx, 0)
|
||||
box_outside = np.intp(box_outside)
|
||||
box_outside = box_outside.reshape((-1, 1, 2)).astype(np.int32)
|
||||
|
||||
# cv2.boxPoints可以将轮廓点转换为四个角点坐标
|
||||
box_reduce = cv2.boxPoints(rect_reduce)
|
||||
startidx = box_reduce.sum(axis=1).argmin()
|
||||
box_reduce = np.roll(box_reduce, 4 - startidx, 0)
|
||||
box_reduce = np.intp(box_reduce)
|
||||
box_reduce = box_reduce.reshape((-1, 1, 2)).astype(np.int32)
|
||||
|
||||
'''
|
||||
提取区域范围内的(x, y)
|
||||
'''
|
||||
mask_inside = np.zeros(binary.shape, np.uint8)
|
||||
cv2.drawContours(mask_inside, [max_contour], 0, 255, -1)
|
||||
cv2.fillPoly(mask_inside, [box_reduce], (255))
|
||||
# cv2.drawContours(mask_inside, [max_contour], 0, 255, -1)
|
||||
# cv2.imshow('mask_inside', mask_inside)
|
||||
# cv2.waitKey(0)
|
||||
pixel_point2 = cv2.findNonZero(mask_inside)
|
||||
# result = np.zeros_like(color_image)
|
||||
select_point = []
|
||||
@ -178,27 +202,8 @@ class Detection:
|
||||
# outlier_cloud.paint_uniform_color([0, 1, 0])
|
||||
# o3d.visualization.draw_geometries([inlier_cloud, outlier_cloud])
|
||||
|
||||
'''
|
||||
拟合最小外接矩形,计算矩形中心
|
||||
'''
|
||||
|
||||
rect = cv2.minAreaRect(max_contour)
|
||||
# cv2.boxPoints可以将轮廓点转换为四个角点坐标
|
||||
box = cv2.boxPoints(rect)
|
||||
|
||||
# 这一步不影响后面的画图,但是可以保证四个角点坐标为顺时针
|
||||
startidx = box.sum(axis=1).argmin()
|
||||
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]]]
|
||||
box = box_reduce + [[[box_x1, box_y1]], [[box_x1, box_y1]], [[box_x1, box_y1]], [[box_x1, box_y1]]]
|
||||
box_outside = box_outside + [[[box_x1, box_y1]], [[box_x1, box_y1]], [[box_x1, box_y1]], [[box_x1, box_y1]]]
|
||||
|
||||
box[0][0][1], box[0][0][0] = out_bounds_dete(pm.shape[0], pm.shape[1], box[0][0][1], box[0][0][0])
|
||||
box[1][0][1], box[1][0][0] = out_bounds_dete(pm.shape[0], pm.shape[1], box[1][0][1], box[1][0][0])
|
||||
@ -226,6 +231,7 @@ class Detection:
|
||||
uv.append([x_rotation_center, y_rotation_center])
|
||||
seg_point.append(pm_seg)
|
||||
cv2.polylines(img, [box], True, (0, 255, 0), 2)
|
||||
cv2.polylines(img, [box_outside], True, (226, 12, 89), 2)
|
||||
|
||||
_idx = find_position(Depth_Z, RegionalArea, 100, True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user