All articles
Computer Vision / AlgoFly Journal

AI for Basketball Analysis: Tracking Players, Shots, and Identity

Inside the engineering decisions behind basketball analytics: camera placement, player reidentification, shot-event sequences, uncertainty, and useful statistics.

AI for Basketball Analysis: Tracking Players, Shots, and Identity — AlgoFly Journal
In this article

A basketball analytics system has to answer questions that a single object detector cannot settle. Who is the player returning to the frame? Was that motion a shot attempt? Did the ball pass through the hoop? Which player should receive the event? Our basketball analysis project video discusses a setup using an iPad below a hoop, player tracking, shot detection, and practical camera arrangements.

The project description specifically highlights reidentifying players after they leave the camera's view and using mirrors to help count shots. Those details make the project interesting: the solution combines scene design, vision, and temporal reasoning. This article develops that architecture and the evaluation questions it raises; it does not present unreported accuracy numbers or a public training pipeline.

Start with what the camera can actually see

The camera position determines which events can be inferred. A low viewpoint near the hoop can capture players approaching the basket, but may not show the entire ball trajectory or enough of the rim to judge every result. People occlude one another, fast motion creates blur, and lighting changes between indoor and outdoor courts.

The mirror arrangement mentioned in the video is a useful example of solving a perception problem physically. Changing the available view can expose evidence that would otherwise be missing. It also introduces another image region with its own geometry and lighting. A reflected player should not become a second person in the same statistics, and reflections need to be distinguished from the primary view.

Before adding a model, record a few representative sessions and list which events are directly visible, partly visible, or impossible to establish from that setup. That exercise can save far more time than increasing model size.

A track ID is not a player identity

Frame from the basketball project showing people on a court with player tracking overlays
A sampled frame from the original project video shows player tracking on court. The source preview is low resolution.

Frame-by-frame detection identifies visible people. Tracking links detections across adjacent frames. Player identity asks a longer-term question: whether someone returning after an occlusion or an exit is the same person as before. Treating those as one step makes statistics fragile, because a tracker may legitimately create a new track when the person reappears.

A useful architecture keeps a short-lived visual track separate from a session-level player record. Appearance, timing, location, and application context can contribute to linking them. When the evidence is weak, keep the association uncertain instead of immediately assigning the event to a confident-looking identity.

Appearance matching also has limits. Similar uniforms, changing poses, motion blur, and partial crops can make different people look alike. A successful reassociation in a short demonstration does not establish reliable identification in a crowded game. Evaluate the conditions the actual product is expected to support.

Recognize a shot as a sequence

Basketball analytics architecture separating detections, temporary tracks, player identity, event evidence, and reviewed statistics
Tracking, identity, and event resolution are separate responsibilities.

A ball near the hoop is not automatically a made basket. A player jumping is not automatically shooting. Event detection needs evidence over time: candidate possession, a release or shot-like motion, subsequent observations, and a resolution. The exact signals depend on which parts of the action the cameras can see.

The following state sketch is an illustrative design pattern, not the project's published implementation:

idle
  -> candidate_attempt
  -> tracking_flight_or_hoop_evidence
  -> resolved_make | resolved_miss | unresolved
  -> idle

The unresolved state matters. When the ball disappears or the rim is occluded, guessing a result pollutes the data. Store the partial event and its evidence so that the application can either request review or exclude it from statistics that require confirmed outcomes.

Debouncing is another practical requirement. A ball may remain in the relevant image region across several frames. The event system should count one attempt, not one detection per frame. Use timestamps and event lifecycle rules, rather than assuming frame rate is constant.

Convert observations into defensible statistics

Player movement can support useful summaries, but the coordinate system changes what the numbers mean. A path in image pixels is not a physical distance traveled on the court. Perspective causes the same world-space movement to cover different pixel distances at different locations.

If the application needs court positions, define a mapping from the relevant image plane to court coordinates and validate it against known points. That mapping applies to points on the court plane; elevated joints or a ball in flight do not automatically obey the same relationship. Make the statistic match the observation available.

Keep raw observations and derived aggregates separable. If a player association is corrected, the system should be able to recompute that player's attempts and movement summaries. Otherwise one identity mistake can remain embedded in many downstream totals.

Design for a sustained session

A mobile-device prototype needs to run for more than a few seconds. Camera capture, decoding, inference, drawing overlays, and storage compete for resources. Measure end-to-end latency and dropped observations across a complete session, including device temperature and changes in lighting or network quality where applicable.

Dropping a display frame is not the same as losing an event. A pipeline can render less frequently while retaining timestamps and enough observations for the event logic. Conversely, a visually smooth overlay can hide delays that cause release and hoop observations to be associated incorrectly. Evaluate the event output, not only the animation.

Test the mistakes that change the score

Build an annotated set of short sessions with player identities, attempts, and outcomes. Include rebounds, passes near the hoop, pump fakes, overlapping players, exits and returns, and sequences where the ball is not visible. Count false attempts and missed attempts separately, then examine attribution and result classification within the detected attempts.

This decomposition helps identify the next engineering step. If most errors begin with identity switches, improving ball detection alone will not fix the statistics. If an event is never visible from the camera, a better position or another view may matter more than another training run.

The video's central lesson is that a sports vision product needs a coherent event system around its models. Scene setup, tracking, identity, uncertainty, and measurement all contribute to whether the final numbers are useful to a player.

Watch and explore

WRITTEN BY

AlgoFly Team

Engineering ideas, practical guides, and the tools we build at AlgoFly.

Explore more articles →