1

I have used ImageAI to detect vehicles in a video and my requirement is to save the detected vehicles in a sperate folder as images as the video is being processed. The code which I have used is given.

from imageai.Detection import VideoObjectDetection
import os

execution_path = os.getcwd()

detector = VideoObjectDetection()
detector.setModelTypeAsTinyYOLOv3()
detector.setModelPath( os.path.join(execution_path , "yolo-tiny.h5"))
detector.loadModel()

custom_objects = detector.CustomObjects( motorcycle=True, car=True, bus=True,truck=True,)

video_path = detector.detectCustomObjectsFromVideo(custom_objects=custom_objects, 
                                input_file_path=os.path.join(execution_path, 
                               'C:\\Users\\priyan\\Desktop\\Number plate identification\\Test 
                                Videos\\test04.mp4'),output_file_path=os.path.join(execution_path, 
                               "traffic_custom_detected"),frames_per_second=20, log_progress=True)
print(video_path)
Miki
  • 40,887
  • 13
  • 123
  • 202
  • How does the detector returns the detected object? An option would be to use the bounding box of the detected object (frame by frame), crop the frame to this box, and save the resulting image. – jcf Feb 21 '20 at 10:24
  • It's detected in the output video with bounding boxes. I'm quite new to this and I couldn't find a method to input a set of images to detect using ImageAI under object detection for images. – F.L.P.M. Jayawardena Feb 21 '20 at 10:28
  • It would be great if you could elaborate or point me in the right direction – F.L.P.M. Jayawardena Feb 21 '20 at 10:30
  • I haven't worked with the ImageAI module, so I don't know its details. You should try to get the image coordinates of the bounding boxes, frame by frame, and then cropping using an image processor module, like openCV or scikit. Take a look at this question for cropping images given another image (in your case, the bounding box): https://stackoverflow.com/questions/56650685/crop-image-using-mask-and-python-scikit-image – jcf Feb 21 '20 at 10:35
  • It doesn't give an image output all with bounding boxes. Just a video as an output – F.L.P.M. Jayawardena Feb 21 '20 at 10:40

0 Answers0