Bounding Box Motion Update
Implement a solution to update the position of a bounding box based on its predicted motion. The goal is to adjust the box's location in the next frame, given its current position and motion.
In object tracking, predicting the motion of an object is crucial for initializing the search region for template matching. A bounding box is typically represented as [x,y,width,height], where (x,y) denotes the top-left corner. The motion of the object can be described by a motion vector (dx,dy), which represents the change in x and y coordinates.
To update the bounding box position, the following steps are involved:
- Extract the current position (x,y) and dimensions (width,height) of the box.
- Apply the predicted motion by adjusting the position using the motion vector (dx,dy).
This technique is widely used in surveillance systems.
Example:
bbox = [10, 20, 50, 60] motion = (5, -3)
[15, 17, 50, 60]
Applying motion to bounding box:
Original: x=10, y=20, w=50, h=60 Motion: dx=5, dy=-3
Updated position:
- x_new = 10 + 5 = 15
- y_new = 20 + (-3) = 17
Size unchanged:
- w = 50, h = 60
Result: [15, 17, 50, 60]
Constraints:
- bbox: [x, y, width, height]
- motion: (dx, dy) predicted displacement
- Return updated bbox (only x and y change, size stays same)
You can think of this task as: “Given the box’s current position and a motion vector, compute the box’s new top‑left corner, keeping width and height the same.”
1. Background Knowledge
In single-object tracking, the tracker maintains a state for each object, often represented by a bounding box around it in each frame. A simple state is [x,y,w,h], where (x,y) is the top-left corner and w,h are width and height. More advanced trackers extend this state with velocity terms (e.g., x˙,y˙) and use motion models like constant velocity or constant acceleration to predict where the object will be in the next frame.
The motion prediction step uses the current state plus an estimated motion (e.g., displacement in pixels per frame) to estimate a new bounding box in the next frame. This predicted box is not necessarily the final answer; it is often used to define a search region for template matching, correlation filters, or other appearance-based methods that refine the location. But at the core, the simplest prediction just adds the motion to the position.
Because the bounding box is parameterized as [x,y,width,height], basic motion updates typically only change x and y while keeping width and height unchanged for that frame, unless there is also a scale/size motion estimate (e.g., object moving closer/farther or changing shape).
2. Algorithm / Approach
The general pattern for this kind of problem:
- Interpret the motion: Motion is usually given as a 2D displacement (Δx,Δy) in pixel coordinates between consecutive frames (or per time step).
- Apply motion to box position:
- New top-left: (x′,y′)=(x+Δx,y+Δy)
- Keep width and height the same if no scale change is given.
- Optionally clamp or validate: Ensure the new bounding box lies within image bounds and has valid dimensions (non-negative, non-zero).
Continue the full explanation
You're reading the free preview. Unlock the complete walkthrough, the code editor, test runner and reference solution with Premium.
Editor locked
The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.