finish analysis_inference_result

This commit is contained in:
hofee 2024-09-20 18:56:44 +08:00
parent caab57e998
commit 7c713a9c4c

56
app.py
View File

@ -149,6 +149,45 @@ def get_frame_data():
return jsonify({"seq_frame_data": result,"model_pts":model_points.tolist(), "obj_path": obj_path, "mtl_path":mtl_path, "success": True})
def rotation_6d_to_matrix_numpy(d6):
a1, a2 = d6[:3], d6[3:]
b1 = a1 / np.linalg.norm(a1)
b2 = a2 - np.dot(b1, a2) * b1
b2 = b2 / np.linalg.norm(b2)
b3 = np.cross(b1, b2)
return np.stack((b1, b2, b3), axis=-2)
def parse_to_frame_data(inference_result):
result = []
combined_point_cloud = np.zeros((0, 3))
last_CR = 0
for idx in range(len(inference_result["pts_seq"])):
frame_data ={}
pose_9d = inference_result["pred_pose_9d_seq"][idx]
np_pose_9d = np.array(pose_9d)
cam_to_world_mat = np.eye(4)
cam_to_world_mat[:3,:3] = rotation_6d_to_matrix_numpy(np_pose_9d[:6])
cam_to_world_mat[:3, 3] = np_pose_9d[6:]
frame_data['cam_to_world'] = cam_to_world_mat.tolist()
target_pts = inference_result["target_pts_seq"][idx]
coverage_rate = inference_result["coverage_rate_seq"][idx]
frame_data['new_point_cloud'] = target_pts.tolist()
frame_data['combined_point_cloud'] = combined_point_cloud.tolist()
combined_point_cloud = np.concatenate([combined_point_cloud, target_pts], axis=0)
frame_data["coverage_rate"] = float(coverage_rate)
delta_CR = frame_data["coverage_rate"] - last_CR
frame_data["delta_CR"] = round(delta_CR,2)
last_CR = frame_data["coverage_rate"]
result.append({
"frame_id": idx,
"data": frame_data
})
return result
@app.route('/analysis_inference_result', methods=['POST'])
def analysis_inference_result():
res = {"success": True}
@ -170,7 +209,22 @@ def analysis_inference_result():
res["message"] = f"File processing error: {e}"
return jsonify(res)
print(data)
result = parse_to_frame_data(data)
scene_name = data["scene_name"]
res["seq_frame_data"] = result
res["retry_no_pts_pose"] = data["retry_no_pts_pose"]
res["retry_duplication_pose"] = data["retry_duplication_pose"]
dataset_name = "sample"
obj_path = os.path.join(dataset_name, scene_name, 'mesh', 'world_target_mesh.obj')
mtl_path = os.path.join(dataset_name, scene_name, 'mesh', 'material.mtl')
res["obj_path"] = obj_path
res["mtl_path"] = mtl_path
res["max_coverage_rate"] = round(data["max_coverage_rate"]*100, 3)
res["scene_name"] = scene_name
res["pred_max_coverage_rate"] = round(data["pred_max_coverage_rate"]*100, 3)
res["best_seq_len"] = data["best_seq_len"]
return jsonify(res)
if __name__ == '__main__':