修改穹彻技能包mask使用方法

This commit is contained in:
liangyuxuan
2025-11-25 10:56:05 +08:00
parent 5313e92822
commit aa5e2b38db

View File

@@ -320,29 +320,38 @@ class DetectNode(Node):
time3 = time.time()
rgb_bytes = cv2.imencode('.png', rgb_img)[1]
depth_bytes = cv2.imencode('.png', depth_img)[1]
for i, (mask, box) in enumerate(zip(masks, boxes)):
mask = cv2.resize(mask.astype(np.uint8), orig_shape[::-1], interpolation=cv2.INTER_NEAREST)
rgb_crop, depth_crop, mask_crop, (x_min, y_min) = crop_mask_bbox(rgb_img, depth_img, mask, box)
# rgb_crop, depth_crop, mask_crop, (x_min, y_min) = crop_mask_bbox(rgb_img, depth_img, mask, box)
if depth_crop is None:
self.get_logger().error("depth_crop is None")
continue
# if depth_crop is None:
# self.get_logger().error("depth_crop is None")
# continue
depth_img_crop_mask = np.zeros_like(depth_crop)
depth_img_crop_mask[mask_crop > 0] = depth_crop[mask_crop > 0]
# depth_img_crop_mask = np.zeros_like(depth_crop)
# depth_img_crop_mask[mask_crop > 0] = depth_crop[mask_crop > 0]
print(rgb_crop.shape)
print(rgb_crop.dtype)
# print(rgb_crop.shape)
# print(rgb_crop.dtype)
rgb_bytes = cv2.imencode('.png', rgb_crop)[1]
depth_bytes = cv2.imencode('.png', depth_img_crop_mask)[1]
# rgb_bytes = cv2.imencode('.png', rgb_crop)[1]
# depth_bytes = cv2.imencode('.png', depth_img_crop_mask)[1]
contours, _ = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
mask_contours = contours[0].reshape(1, -1, 2)
res = self.aidk_client.set_direct_setting_variables({"one_mask": f"{mask_contours}"})
intrinsics = [
int(self.camera_size[0]),
int(self.camera_size[1]),
self.K[2] - x_min,
self.K[5] - y_min,
# self.K[2] - x_min,
# self.K[5] - y_min,
self.K[2],
self.K[5],
self.K[0],
self.K[4]
]