把这个函数写成一个接口：def target_location (point_cloud,label_path):
    '''
    :param point_cloud: 目标范围内点云的像素坐标（包含深度信息）
    :param label_path: 目标矩形框路径
    :return: 目标在激光雷达坐标系下的三维坐标
    '''
    with open(label_path, 'r') as f:
        data = json.load(f)
    shapes = data.get("shapes", [])
    rectangles = []
    for shape in shapes:
        if shape.get("shape_type") == "rectangle":
            label = shape.get("label")
            points = np.array(shape.get("points"), dtype=np.float32)
            rectangles.append((label, points))
    target_points = []
    #将目标范围内的二维像素点投影至激光雷达坐标系
    for point in point_cloud:
        # 图像中的像素点
        u = int(point[0])
        v = int(point[1])
        depth = point[2]
        pixel_homogeneous = np.array([u, v, 1])
        K_inv = np.linalg.inv(intrinsics)
        normalized_coords = np.dot(K_inv, pixel_homogeneous)
        # 加入深度信息计算相机坐标系下的坐标
        cam_depth = abs(depth) - 1.108562  # 把x坐标的绝对值减去在x轴方向的平移变量的结果作为该点的深度值
        cameras_coords = np.dot(cam_depth, normalized_coords)
        # print("加入深度信息后投影到相机坐标系下的坐标：", cameras_coords)
        # 计算对应点云坐标投影到相机坐标系下的坐标
        # 步骤一：将像素点从图像平面坐标系转换到相机坐标系
        camera_coord = np.append(cameras_coords, 1)
        # 步骤二：将相机坐标系下的点转换到车辆坐标系
        lidar_coords_homogeneous = np.dot(extrinsics_cam2lidar, camera_coord)
        lidar_coords = lidar_coords_homogeneous[:3]
        target_points.append(lidar_coords)
        #print("在激光雷达坐标系下的坐标:", lidar_coords)
        eps = 0.3  # 邻域半径参数，可根据数据实际情况调整
        min_samples = 50  # 最小样本数参数，可根据数据实际情况调整
    dbscan = DBSCAN(eps=eps, min_samples=min_samples).fit(target_points)
    labels = dbscan.labels_
    unique_labels = np.unique(labels)
    centers = []
    target_points= np.array(target_points)
    for label in unique_labels:
        if label != -1:
            cluster_points = target_points[labels == label]
            center = np.mean(cluster_points, axis=0).tolist()
            centers.append(center)
    center_decide = []
    area_rec = []
    #把目标点云投影到图像上
    target_points_2d, _ = cv2.projectPoints(np.array(target_points), rvec, tvec, intrinsics, distCoeffs)
    #给投影后的二维点加上聚类标签
    # 用于保存与矩形相交的聚类中心点
    final_centers = []
    # print("Type of rectangles:", type(rectangles))
    # for i, rect in enumerate(rectangles):
    #     print(f"Type of rect #{i}:", type(rect))  # 查看每个矩形的类型和结构
    #     print(f"Content of rect #{i}:", rect)
    # 遍历每个矩形
    for rect_tuple in rectangles:
        # label = rect_tuple[0]  # 获取标签
        rect_points = rect_tuple[1]  # 获取矩形的坐标数组
        # 确保 rect_points 是一个 numpy 数组
        if isinstance(rect_points, np.ndarray):
            x_min = np.min(rect_points[:, 0])  # 获取矩形的最小 x 坐标
            y_min = np.min(rect_points[:, 1])  # 获取矩形的最小 y 坐标
            x_max = np.max(rect_points[:, 0])  # 获取矩形的最大 x 坐标
            y_max = np.max(rect_points[:, 1])  # 获取矩形的最大 y 坐标
        else:
            print(f"Expected a numpy array for rectangle points, got: {type(rect_points)}")

        intersection_centers = []  # 保存与当前矩形相交的聚类中心点及其IoU

        for label in unique_labels:
            if label != -1:
                cluster_points_2d = target_points_2d[labels == label]
                cluster_points_2d = cluster_points_2d.reshape(-1, 2)
                # print(cluster_points_2d)
                # print(f"Shape of cluster_points_2d: {cluster_points_2d.shape}")
                x1_min = np.min(cluster_points_2d[:, 0])
                x1_max = np.max(cluster_points_2d[:, 0])
                y1_min = np.min(cluster_points_2d[:, 1])
                y1_max = np.max(cluster_points_2d[:, 1])

                # 检查包围盒与矩形相交
                if not (x1_max < x_min or x_max < x1_min or y1_max < y_min or y_max < y1_min):
                    # 计算交集区域的坐标
                    intersection_x_min = max(x1_min, x_min)
                    intersection_x_max = min(x1_max, x_max)
                    intersection_y_min = max(y1_min, y_min)
                    intersection_y_max = min(y1_max, y_max)

                    # 计算交集面积
                    intersection_area = max(0, intersection_x_max - intersection_x_min) * max(0,
                                                                                              intersection_y_max - intersection_y_min)

                    # 计算并集面积
                    box1_area = (x1_max - x1_min) * (y1_max - y1_min)  # 当前聚类的面积
                    box2_area = (x_max - x_min) * (y_max - y_min)  # 矩形的面积
                    union_area = box1_area + box2_area - intersection_area

                    # 计算交并比（IoU）
                    intersection_union = intersection_area / union_area if union_area > 0 else 0

                    # 获取三维聚类中心
                    center_3d = np.mean(target_points[labels == label], axis=0).tolist()
                    intersection_centers.append((center_3d, intersection_union))

        # 根据条件选择最终保留的中心点
        if intersection_centers:
            if len(intersection_centers) > 1:
                # 选择交并比最大者
                best_center = max(intersection_centers, key=lambda x : x[1])[0]
            else:
                # 只与一个聚类相交，直接取该聚类的中心点
                best_center = intersection_centers[0][0]

            final_centers.append(best_center)
    # final_centers 包含了最终代表每个矩形的聚类中心点
    return final_centers,target_points,labels