def do_show_new_camera_calibration_extrinsic_dialog2(new_name: str, camera_pose, display_image, core: "PyriWebUIBrowser"): try: camera_calib = core.device_manager.get_device_subscription("vision_camera_calibration").GetDefaultClient() dialog2_html = importlib_resources.read_text(__package__,"new_calibrate_extrinsic_dialog2.html") el = js.document.createElement('div') el.id = "new_calibrate_extrinsic_dialog2_wrapper" js.document.getElementById("wrapper").appendChild(el) def handle_hidden(*args): try: el.parentElement.removeChild(el) except: traceback.print_exc() geom_util = GeometryUtil(client_obj=camera_calib) xyz, rpy1, _, _ = geom_util.named_pose_to_xyz_rpy(camera_pose.pose) rpy = np.rad2deg(rpy1) x = f"{xyz[0]:4e}" y = f"{xyz[1]:4e}" z = f"{xyz[2]:4e}" r_r = f"{rpy[0]:4e}" r_p = f"{rpy[1]:4e}" r_y = f"{rpy[2]:4e}" i=0 d_encoded = str(base64.b64encode(display_image.data))[2:-1] disp_img_src = "data:image/jpeg;base64," + d_encoded # TODO: check for png? dialog = js.Vue.new(js.python_to_js({ "el": "#new_calibrate_extrinsic_dialog2_wrapper", "template": dialog2_html, "data": { "x": x, "y": y, "z": z, "r_r": r_r, "r_p": r_p, "r_y": r_y, "disp_img": disp_img_src }, "methods": { "handle_hidden": handle_hidden } })) dialog["$bvModal"].show("new_vision_camera_calibrate_extrinsic2") except: traceback.print_exc()
c = d.get_device_client("vision_template_matching", 1) bounding_box2d_type = RRN.GetStructureType( 'com.robotraconteur.geometry.BoundingBox2D', c) named_pose2d_type = RRN.GetStructureType( 'com.robotraconteur.geometry.NamedPose2D', c) pose2d_dtype = RRN.GetNamedArrayDType('com.robotraconteur.geometry.Pose2D', c) var_storage = d.get_device_client("variable_storage", 1) roi = var_storage.getf_variable_value("globals", roi_name).data #res = c.match_template_stored_image("extrinsic_image0", "test10", None) res = c.match_template_world_pose_camera_capture( "camera", template_name, "camera_calibration_intrinsic", "camera_calibration_extrinsic", 0, None) img_util = ImageUtil(client_obj=c) res_img = img_util.compressed_image_to_array(res.display_image) geom_util = GeometryUtil(client_obj=c) xyz, rpy, _, _ = geom_util.named_pose_to_xyz_rpy( res.template_matches[0].pose.pose) cv2.imshow("", res_img) cv2.waitKey() cv2.destroyAllWindows() print(res)
def do_show_new_robot_origin_calibration_dialog2(new_name: str, robot_pose, display_images, core: "PyriWebUIBrowser"): try: dialog2_html = importlib_resources.read_text( __package__, "new_calibrate_robot_origin_dialog2.html") robot_calib = core.device_manager.get_device_subscription( "vision_robot_calibration").GetDefaultClient() geom_util = GeometryUtil(client_obj=robot_calib) marker_xyz, marker_rpy, _, _ = geom_util.named_pose_to_xyz_rpy( robot_pose.pose) el = js.document.createElement('div') el.id = "new_calibrate_robot_origin_dialog2_wrapper" js.document.getElementById("wrapper").appendChild(el) def handle_hidden(*args): try: el.parentElement.removeChild(el) except: traceback.print_exc() x = f"{marker_xyz[0]:4e}" y = f"{marker_xyz[1]:4e}" z = f"{marker_xyz[2]:4e}" r_r = f"{marker_rpy[0]:4e}" r_p = f"{marker_rpy[1]:4e}" r_y = f"{marker_rpy[2]:4e}" imgs = [] i = 0 for d in display_images: d_encoded = str(base64.b64encode(d.data))[2:-1] d2 = { "id": i, "caption": f"Calibration result {i+1}", "img": "data:image/jpeg;base64," + d_encoded } del d_encoded imgs.append(d2) i += 1 #TODO: check for png? dialog = js.Vue.new( js.python_to_js({ "el": "#new_calibrate_robot_origin_dialog2_wrapper", "template": dialog2_html, "data": { "x": x, "y": y, "z": z, "r_r": r_r, "r_p": r_p, "r_y": r_y, "display_images": imgs }, "methods": { "handle_hidden": handle_hidden } })) dialog["$bvModal"].show("new_vision_camera_calibrate_robot_origin2") except: traceback.print_exc()