PIXELBANKv9.1.0
Menu

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][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:

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)
🔒

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

0/0
Run code to see test results.
Bounding Box Motion Update - Easy | PixelBank