baseball-engine / docs /PITCHER_FLOOR_DIRECTION.md
github-actions[bot]
Automated Deploy: 3ea2037ab7d55d5b498f7e2ea0336818fc24f725
fe40b87
|
Raw History Blame Contribute Delete
16.3 kB

Pitcher direction from two floor points

Motion API 1.14.0 · SAM 3D Body and GVHMR · 19 October 2026

Automatic direction (default)

Updated 30 October 2026. Normal motion uploads omit pitcher_vector, pitcher_source, and pitcher_floor_points. Both SAM and GVHMR now run automatic_body_swing_direction_v2 on their corrected 3D body tracks before calculating/exporting measurements. The old home-plate detector is no longer called. There are no new request fields, downloads, or user prompts.

The estimator uses shoulders, hips, and both wrists. It finds a stable loaded setup before a hand-speed peak, projects the setup hip line onto the horizontal plane, and resolves its direction using the loaded hand side. Both wrists must then move across toward the other side while the hips and shoulders turn in the same swing direction. Several consecutive setup and extension frames must agree. V2 selects the latest five consecutive loaded setup frames that pass the existing 12-degree stability check. A longer preparation stretch can include a walk-in or gradual body turn; its total angular spread no longer invalidates a later stable setup. The reference uses the local interval, so earlier preparation does not bias its heading. The selected interval and the longer search interval are both recorded. Backward loading peaks still fail the forward-motion check; neither that check nor the stability threshold was relaxed. Separate accepted swings must agree within 20 degrees. Missing/rejected points, filter boundaries, model sequence breaks, and timestamp gaps cannot connect a setup to a later swing. Cropped feet are allowed: stride never defines the axis. Handedness and camera intrinsics are not inputs to this estimator. Relative movement checks do not require a physical scale or original recording speed.

An accepted vertical reference is still needed. GeoCalib supplies it when omitted; an explicit up vector also works. Camera movement declared or detected by refinement blocks this reference. Acceptance does not declare the camera fixed or bypass existing camera-stability, timing, scale, or reviewed-event requirements.

On acceptance, coordinates.pitcher_estimation contains automatic: true, status: estimated, the method, setup/peak/extension frame indices, turn angles, hand progress, agreement checks and assumptions. reference_kind is estimated_batting_direction; target_alignment_verified is false. Effective pipeline.calculation_inputs receive the vector and generated source; submitted pipeline.inputs stay unchanged. Replay and measurements use that same vector. When the axis is used, the coordinate frame is estimated_batting_axes, with positive X named estimated_hitting_direction. Relevant measurements carry pitcher_reference_estimated_from_body_motion and target_alignment_unverified. Explicit vectors and manual floor selections retain precedence.

Limits: this is a deterministic body-motion heuristic, not a trained baseball direction model. It assumes the setup hip line approximately follows the intended hitting direction. Open/closed setups, unusual drills, inaccurate model depth, and movement that resembles a swing can bias or fool it. Body motion alone cannot verify the actual direction to an unseen pitcher. A clipped swing without a clear setup or extension, conflicting repetitions, or missing vertical leaves the direction null; normal motion export continues. Do not interpret this axis as independent evidence that the athlete's setup is aligned correctly with a target.

accuracy_validated stays false and confidence stays null. reliable means the engineering acceptance checks passed, not a calibrated accuracy probability. Synthetic tests cover both batting sides, camera rotations, missing evidence, motion conflicts, and replay consistency. Independently labelled real videos are still required to measure accuracy and false positives.

Optional manual override

Use the existing /v1/motion-analyses upload and /revisions routes. Select a decoded source frame and two points on the same level floor: first near the batter, then farther along the floor toward the pitcher. They need not be at the pitcher's feet. Their order defines the positive direction; reversing the points reverses the vector. This is a field direction, not the ball trajectory.

Request

Add pitcher_floor_points to the multipart form's options JSON. Example for an illustrative 1920 × 1080 source, with illustrative calibration values; use the actual camera's calibration rather than copying these numbers:

{
  "model": "gvhmr",
  "annotated_videos": true,
  "camera_stability": "fixed_verified",
  "camera": {
    "fx": 1100,
    "fy": 1050,
    "cx": 925,
    "cy": 500,
    "source": "Calibration procedure and recording configuration",
    "calibration_status": "calibrated",
    "distortion": [0, 0, 0, 0, 0]
  },
  "pitcher_floor_points": {
    "source_frame_index": 40,
    "near_batter": [650, 893.75],
    "toward_pitcher": [1291.666666667, 762.5],
    "selection_uncertainty_px": 2,
    "up_sensitivity_deg": 1
  }
}

Use "model":"sam3d" for SAM; every other field and response stays the same. Omit up_vector/up_source to use the existing automatic GeoCalib estimate. Alternatively supply the known camera-space up vector and its source. An unreliable or missing up reference leaves the floor direction unknown.

Field Contract
pitcher_floor_points Optional object; omit/null when no selection is available.
source_frame_index Required, zero-based decoded source frame index, integer ≥ 0. Both points belong to this frame.
near_batter Required [x,y], upright original source-image pixels, first point.
toward_pitcher Required [x,y], same frame/pixel convention, second point.
selection_uncertainty_px Optional positive perturbation radius per pixel coordinate; default 2 source pixels, maximum 25. Increase for coarse selections. This is a sensitivity assumption, not measured click accuracy.
up_sensitivity_deg Optional positive up-direction perturbation angle; default 1°, maximum 30°. For estimated up, the calculation uses at least the model uncertainty plus frame disagreement; this field cannot lower that test.
camera.calibration_status New motion-only field: unknown (default), estimated, or calibrated. Floor direction requires calibrated; set this only for calibration that applies to this recording's upright image, crop, resolution, zoom and lens configuration.
camera.fx/fy/cx/cy/source Existing camera calibration fields. Focal lengths and principal point are in upright source-image pixels. A source description is required.
camera.distortion Existing optional Brown–Conrady [k1,k2,p1,p2,k3]. Omitted/null means a pinhole assumption; use it only when appropriate for the calibrated source.
pitcher_vector/pitcher_source Existing manual override. When supplied, it wins over floor points, even if floor points/calibration would be unusable. Original values and magnitude stay unchanged.

calibration_status does not change existing body reconstruction or up estimation. Older motion requests continue to work, defaulting it to unknown; they cannot silently promote a guessed focal length into floor calibration. For this manual floor-point path, SAM/GVHMR body-model intrinsics and GeoCalib's internal focal estimate are not substituted for the required declared calibration. This option belongs to the motion API; legacy SAM/coaching request contracts remain separate.

Frontend coordinate mapping

Use source_video.display_width/display_height and the upright source frame. Coordinates are not CSS pixels, raw rotated-file pixels, the skeleton's 3D coordinates, or the smaller annotated-video dimensions. Account for preview scaling, cropping, and letterboxing:

x_source = (x_in_preview - content_left) * source_width / content_width
y_source = (y_in_preview - content_top)  * source_height / content_height

Undo any frontend-only mirror transform before sending coordinates. The backend does not mirror selections. Select the source-frame index using the returned frame records and actual source/video timestamps; do not calculate it from currentTime * FPS, because the recording can have variable frame timing. Both points must come from the same displayed frame and actually touch the floor, not a knee, elevated tee, distant wall, or projected line above the ground.

To add or correct points after an analysis, submit:

{
  "options": {
    "pitcher_floor_points": {
      "source_frame_index": 40,
      "near_batter": [650, 893.75],
      "toward_pitcher": [1291.666666667, 762.5]
    },
    "pitcher_vector": null,
    "pitcher_source": null
  }
}

Send this to POST /v1/motion-analyses/{job_id}/revisions. Clearing a previous manual vector is necessary to enable floor estimation. Existing calibration and other recording facts are inherited. The parent stays immutable. Point-only changes can reuse verified native inference; calibration changes may require new inference. To remove the selection, revise pitcher_floor_points to null.

Response

Read the completed manifest's coordinates. The following is an illustrative excerpt; actual vectors and diagnostics depend on the recording and selection:

{
  "pitcher_vector": [0.8320502943, 0, 0.5547001962],
  "pitcher_source": "Two user-selected floor points at source frame 40; calibrated ray-plane intersection with level floor and camera above floor (estimated)",
  "pitcher_vector_frame": "upright_camera_x_right_y_down_z_away",
  "pitcher_estimation": {
    "status": "estimated",
    "method": "two_floor_points_ray_plane_v1",
    "applied": true,
    "reliable": true,
    "confidence": null,
    "accuracy_validated": false,
    "reason_code": null
  }
}

The full pitcher_estimation also repeats its vector/source. Additional diagnostics are present when their validation stage was reached; they are optional for unknown results:

  • selection and source_frame: original selection, actual source-frame index, dimensions, PTS/time base and video timestamp.
  • camera_calibration, up_vector_used, up_reference_status: inputs used by the geometry. The up vector here is normalized for calculation.
  • ray_floor_incidence_deg, pixel_separation_px, maximum_undistortion_residual_px: geometric checks.
  • up_sensitivity_deg_used, maximum_direction_deviation_deg, evaluated_scenarios, sensitivity_kind, and limits: sensitivity diagnostics and the acceptance thresholds.
  • assumptions, floor_points_verified_by_backend: false, calibration_accuracy_verified_by_backend: false, and the implementation hash.

Display Estimated pitcher direction for status: estimated. Derived vectors are normalized and in camera axes x right, y down, z away. They are not in the rotated skeleton/export axes. reliable: true means the conditional engineering checks passed; it is not a probability or independent accuracy validation. Keep confidence: null as unknown, not 0%.

For provided, display User-supplied pitcher direction. The vector/source remain exact, method is caller_supplied, and reliable is null. For unknown, both effective vector and source are null, applied/reliable are false, and reason_code explains why. Do not turn the 2D arrow into a substitute vector. Older cached manifests may omit these new keys. Treat an absent reference as unknown and offer a new analysis/revision; do not rewrite an immutable result.

Original validated facts remain in pipeline.inputs; the derived vector/source are added only to pipeline.calculation_inputs. The same reference is included as pitcher_reference in measurement and quality artifacts. Measurement summaries and series contain pitcher_reference_status; available field-axis-dependent summaries carry pitcher_reference_estimated_from_floor_points.

Accepted direction sets the measurement/export X axis toward the pitcher. The existing frame identifier declared_field_axes remains for compatibility; pitcher_estimation.status records whether that field axis was derived or manually provided. Measurements and public-artifact reproduction use the same effective reference. Physical clock, body-point quality, scale, reviewed events, and other measurement guards still apply. This direction does not provide ground positions, camera height, floor distances, or a calibrated ground trajectory.

Calculation and rejection checks

Undistort the two pixels using the supplied calibration, then form optical rays r = [x_normalized, y_normalized, 1]. With normalized camera-up u and a camera at positive unknown height h above the level floor, the floor plane is u·X = -h. Each hit is X = -h*r/(u·r). Therefore:

q_near   = -r_near   / dot(u, r_near)
q_toward = -r_toward / dot(u, r_toward)
pitcher_vector = normalize(q_toward - q_near)

Height cancels, while perspective and the first-to-second sign are retained. Subtracting raw pixel positions or projecting a 2D arrow onto the floor is not this calculation. Pixel/ray and distortion conventions follow the OpenCV camera model.

Acceptance requires fixed verified camera orientation, no observed static-camera conflict, a valid source index, consistent source dimensions, in-image points at least 10 pixels apart, declared calibrated intrinsics, plausible focal/principal point values, finite monotonic distortion geometry, ≤ 0.1-pixel undistortion round-trip error, and both floor rays at least 3° below the horizon.

The backend perturbs each click coordinate by its selection uncertainty and samples an up-direction cone at 16 azimuths plus its center: 289 combined scenarios. Every sampled ray must still hit a well-conditioned visible floor; the maximum direction change must be ≤ 10°. These are engineering gates, not guaranteed error bounds. A consistent wrong calibration, wrong up direction, sloping/nonplanar floor, or a tap on an elevated object can still produce a wrong direction. The backend cannot establish those facts from two clicks.

Common unknown reasons:

reason_code FE action
floor_points_not_supplied Offer the two-point selection.
floor_source_frame_out_of_range Re-select a source frame from this recording.
floor_points_outside_source_image Correct preview-to-source coordinate mapping.
floor_point_uncertainty_outside_source_image Select points farther from image borders.
floor_points_too_close Select floor points farther apart.
floor_points_not_below_horizon Select visible floor below the horizon; check up/calibration.
floor_points_too_near_horizon Choose nearer, better-conditioned floor points.
camera_not_fixed_for_pitcher_reference Verify a fixed recording or re-record with a fixed camera.
source_image_dimensions_changed Supply a recording/calibration with consistent source dimensions.
pitcher_camera_calibration_missing Provide applicable camera calibration.
pitcher_camera_calibration_unverified Use verified calibration; do not relabel guessed intrinsics.
pitcher_camera_calibration_implausible Check focal lengths, principal point, crop and resolution.
camera_undistortion_unreliable, camera_distortion_not_monotonic Check the lens model/calibration.
pitcher_up_reference_unknown, pitcher_up_reference_unreliable, pitcher_up_uncertainty_unknown Resolve the up reference before estimating direction.
floor_direction_uncertainty_unreliable, floor_direction_uncertainty_too_high Use a better-separated selection away from the horizon; check up/calibration.
floor_direction_geometry_failed, invalid_direction_geometry Recheck the selection and calibration.

Geometrically unusable inputs leave this reference unknown without failing an otherwise usable motion analysis. Malformed JSON/options still return 422; ordinary upload, native-model, queue and artifact errors keep their existing semantics. Capabilities expose pitcher_direction_from_floor_points.