pythonopencvobject-detectionvideo-processingvideo-tracking

How to draw bounding boxes on a video when its coordinates and frame numbers are extracted in csv?


I have extracted all the bounding boxes using an object detector in a CSV file with the following format:

<Column 1>   <Column 2>    <Column 3>    <Column 4>    <Column 5>  
<Frame no>   <x_topleft>   <y_topleft>   <width>       <height>
     1        649.44        231.5         44.42       86.13
     1        252.78        207.73        35.81       96.64
     2        623.80        251.74        36.10       70.51
     :          :             :             :           :    
     :          :             :             :           :

How can I draw these bounding boxes on its respective frames in the video. I would also like to save the output in the form of a video with bounding boxes drawn for all the frames.


Solution

  • What you are looking for is the rectangle function in OpenCV in combination with VideoWriter class that allows to write videos (with various encoding methods).