Extract object and save it as an image.png using c++

asked 2019-11-19 11:13:41 -0600

zakaziko gravatar image

HI Forum , Actually I work on a car detection project at real time, when I launch the camera I want to make a screenshot (.png) for any car and save it in a path, which means i need a function in opencv that does the screenshot of just a car detected (not all windows).

Suppose you have the following image:

image description

Now i want to extract to individual images each of the independent cars, like this for example:

image description

NB: i have a function can be detect object and draw a contour of each object is FeatureTracker() , i would use it for extracting image and save it in path/image.png

Thanks in advice

edit retag flag offensive close merge delete

Comments

You already have the car detection routine ? has bounding boxes ? you can copy the bounding box ROI and save it .

Ziri gravatar imageZiri ( 2019-11-21 03:07:43 -0600 )edit

Thanks for your reply Ziri , could you please take look a few minute at this project https://github.com/JdeRobot/traffic-m... ,, i want to add this function here.

zakaziko gravatar imagezakaziko ( 2019-11-21 04:11:03 -0600 )edit

If you've successfully ran that code check blob.h and track where void calculate_blob_center() or get_rect() are called ;

Use Their returned coordinates to do something like this :

SrcImage = imread(""); Rect Car_roi = Rect(leftCornerX, leftCornerY, BoxWidth, BoxHeight); Mat Car_roi_image = SrcImage (Car_roi );

Ziri gravatar imageZiri ( 2019-11-21 18:54:26 -0600 )edit

Hi @Ziri i'm sorry for the delay , i tried follow your answer but not work , I tried to add the function imwrite("/path/image",output) in file viewgtk.cpp line 312 , it's work but the result of image is blur like this image file:///home/bpros/Desktop/04-12-2019%2018-55-40.png , any idea to improve quality of images + remove the blur ,

zakaziko gravatar imagezakaziko ( 2019-12-11 13:18:21 -0600 )edit

keep reminder!! @Ziri

zakaziko gravatar imagezakaziko ( 2019-12-23 03:12:57 -0600 )edit