v9.1.1
Menu

Bounding Box Motion Update

easyPROObject TrackingTrackingCV: Motion Estimation

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][x, y, width, height], where (x,y)(x, y) denotes the top-left corner. The motion of the object can be described by a motion vector (dx,dy)(dx, dy), which represents the change in xx and yy coordinates.

To update the bounding box position, the following steps are involved:

  1. Extract the current position (x,y)(x, y) and dimensions (width,height)(width, height) of the box.
  2. Apply the predicted motion by adjusting the position using the motion vector (dx,dy)(dx, dy).
xnew=x+dxynew=y+dy\begin{aligned} x_{new} &= x + dx \\ y_{new} &= y + dy \end{aligned}

This technique is widely used in surveillance systems.

Example

Input
bbox = [10, 20, 50, 60]
motion = (5, -3)
Output
[15, 17, 50, 60]
Reasoning
  • bbox describes the box in the current frame: its top-left corner sits at (x,y)=(10,20)(x, y) = (10, 20) and it is 5050 pixels wide and 6060 pixels tall.
  • motion is the predicted displacement (dx,dy)=(5,−3)(dx, dy) = (5, -3): the object moves 55 pixels right and 33 pixels up (image yy grows downward, so a negative dydy means upward).
  • Shift the corner: xnew=10+5=15x_{new} = 10 + 5 = 15 and ynew=20+(−3)=17y_{new} = 20 + (-3) = 17.
  • A translation moves every point of the box by the same amount, so its size does not change: width stays 5050, height stays 6060.
  • The output keeps the same four-number layout [x,y,width,height][x, y, width, height], giving [15, 17, 50, 60].
  • Notice that only the first two entries change. With zero motion (0,0)(0, 0) the box comes back exactly as it went in.

Constraints

  • bbox: [x, y, width, height]
  • motion: (dx, dy) predicted displacement
  • Return updated bbox (only x and y change, size stays same)

Learn this in

More from CV: Motion Estimation

PRO

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.

solution.py

Test results

Sign in to run your code against the test cases.