def _get_frame_gt(dataset_objects: List[bpy.types.Mesh], unit_scaling: float, ignore_dist_thres: float, destination_frame: List[str] = ["X", "-Y", "-Z"]): """ Returns GT pose annotations between active camera and objects. :param dataset_objects: Save annotations for these objects. :param unit_scaling: 1000. for outputting poses in mm :param ignore_dist_thres: Distance between camera and object after which object is ignored. Mostly due to failed physics. :param destination_frame: Transform poses from Blender internal coordinates to OpenCV coordinates :return: A list of GT camera-object pose annotations for scene_gt.json """ H_c2w_opencv = Matrix( WriterUtility.get_cam_attribute( bpy.context.scene.camera, 'cam2world_matrix', local_frame_change=destination_frame)) frame_gt = [] for obj in dataset_objects: H_m2w = Matrix( WriterUtility.get_common_attribute(obj, 'matrix_world')) cam_H_m2c = H_c2w_opencv.inverted() @ H_m2w cam_R_m2c = cam_H_m2c.to_quaternion().to_matrix() cam_t_m2c = cam_H_m2c.to_translation() # ignore examples that fell through the plane if not np.linalg.norm(list(cam_t_m2c)) > ignore_dist_thres: cam_t_m2c = list(cam_t_m2c * unit_scaling) frame_gt.append({ 'cam_R_m2c': list(cam_R_m2c[0]) + list(cam_R_m2c[1]) + list(cam_R_m2c[2]), 'cam_t_m2c': cam_t_m2c, 'obj_id': obj["category_id"] }) else: print('ignored obj, ', obj["category_id"], 'because either ') print( '(1) it is further away than parameter "ignore_dist_thres: ",', ignore_dist_thres) print( '(e.g. because it fell through a plane during physics sim)' ) print('or') print('(2) the object pose has not been given in meters') return frame_gt
def _get_frame_gt(dataset_objects, unit_scaling, ignore_dist_thres, destination_frame=["X", "-Y", "-Z"]): """ Returns GT pose annotations between active camera and objects. :return: A list of GT annotations. """ H_c2w_opencv = Matrix( WriterUtility.get_cam_attribute(bpy.context.scene.camera, 'cam2world_matrix', destination_frame)) frame_gt = [] for obj in dataset_objects: H_m2w = Matrix( WriterUtility.get_common_attribute(obj, 'matrix_world')) cam_H_m2c = H_c2w_opencv.inverted() @ H_m2w cam_R_m2c = cam_H_m2c.to_quaternion().to_matrix() cam_t_m2c = cam_H_m2c.to_translation() # ignore examples that fell through the plane if not np.linalg.norm(list(cam_t_m2c)) > ignore_dist_thres: cam_t_m2c = list(cam_t_m2c * unit_scaling) frame_gt.append({ 'cam_R_m2c': list(cam_R_m2c[0]) + list(cam_R_m2c[1]) + list(cam_R_m2c[2]), 'cam_t_m2c': cam_t_m2c, 'obj_id': obj["category_id"] }) else: print('ignored obj, ', obj["category_id"], 'because either ') print( '(1) it is further away than parameter "ignore_dist_thres: ",', ignore_dist_thres) print( '(e.g. because it fell through a plane during physics sim)' ) print('or') print('(2) the object pose has not been given in meters') return frame_gt