void PointerMapper::compute(HandResolver& hand_resolver, Reprojector& reprojector) { active = false; if (calibrated) { float dist_max = value_store.get_float("dist_max", 0); float dist = get_distance(pt_palm, pt_index); float ratio = dist / dist_max; // COUT << ratio << endl; } else { float dist_max = value_store.get_float("dist_max", 0); float dist = get_distance(pt_palm, pt_index); if (dist > dist_max) dist_max = dist; value_store.set_float("dist_max", dist_max); } pt_palm = reprojector.reproject_to_3d(hand_resolver.pt_precise_palm0.x, hand_resolver.pt_precise_palm0.y, hand_resolver.pt_precise_palm1.x, hand_resolver.pt_precise_palm1.y); compute_cursor_point(index_down, hand_resolver.pt_precise_index0, hand_resolver.pt_precise_index1, pt_index, reprojector, pt_cursor_index, dist_cursor_index_plane, actuate_dist, "compute_index"); compute_cursor_point(thumb_down, hand_resolver.pt_precise_thumb0, hand_resolver.pt_precise_thumb1, pt_thumb, reprojector, pt_cursor_thumb, dist_cursor_thumb_plane, actuate_dist + 10, "compute_thumb"); if (pt_cursor_index.y > 1500) { pose_name = ""; index_down = false; } if (calibrated) { if (!index_down) thumb_down = false; compute_pinch_to_zoom(hand_resolver); } }
void PointerMapper::compute_cursor_point(bool& target_down, Point2f& pt_target0, Point2f& pt_target1, Point3f& pt_target, Reprojector& reprojector, Point2f& pt_cursor, float& dist_cursor_target_plane, const float actuation_dist, string name) { LowPassFilter* low_pass_filter = value_store.get_low_pass_filter("low_pass_filter" + name); if (do_reset) { do_reset = false; low_pass_filter->reset(); } if (pt_target0.x != -1 && pt_target1.x != -1) { active = true; pt_target = reprojector.reproject_to_3d(pt_target0.x, pt_target0.y, pt_target1.x, pt_target1.y); if (calibrated) { Point3f pt_target_projected; float dist_target_plane; project_to_plane(pt_target, pt_target_projected, dist_target_plane); rect_warper.warp(pt_target_projected.x, pt_target_projected.y, pt_cursor.x, pt_cursor.y); if (value_store.has_point2f("pt_cursor" + name)) { Point2f temp = value_store.get_point2f("pt_cursor" + name); float alpha = get_distance(pt_cursor, temp) / 1000; if (alpha < 0.05) alpha = 0.05; else if (alpha > 1) alpha = 1; // low_pass_filter->compute(alpha, 0.5, "alpha" + name); low_pass_filter->compute(pt_cursor, alpha, "pt_cursor" + name); } value_store.set_point2f("pt_cursor" + name, pt_cursor); float hit_dist = compute_hit_dist(pt_target_projected); dist_cursor_target_plane = dist_target_plane - hit_dist; low_pass_filter->compute(dist_cursor_target_plane, 0.2, "dist_cursor_target_plane"); float hit_dist_processed = hit_dist; // float hit_dist_processed_old = value_store.get_float("hit_dist_processed_old" + name, hit_dist_processed); // hit_dist_processed += ((hit_dist_processed - hit_dist_processed_old) * 0.25); // value_store.set_float("hit_dist_processed_old" + name, hit_dist_processed); float dist_cursor_target_plane_no_lowpass = dist_target_plane - hit_dist_processed; if (dist_cursor_target_plane_no_lowpass <= actuation_dist + 2) value_store.set_bool("actuated" + name, true); if (value_store.get_bool("actuated" + name)) { target_down = true; if (dist_cursor_target_plane_no_lowpass > actuation_dist + 5) { target_down = false; value_store.set_bool("actuated" + name, false); } } } } else low_pass_filter->reset(); }