OlafenwaMoses / ImageAI

A python library built to empower developers to build applications and systems with self-contained Computer Vision capabilities
https://www.genxr.co/#products
MIT License
8.58k stars 2.19k forks source link

Saving video in RGB #520

Open Andrew2798 opened 4 years ago

Andrew2798 commented 4 years ago

When I run the code below, I get the video in blue shades. I believe that this is due to the fact that opencv works in the BGR space, is it possible to save the video in ImageAI in the BGR space?

from imageai.Detection import VideoObjectDetection
import os

execution_path = os.getcwd()
detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath( os.path.join(execution_path , "yolo.h5"))
detector.loadModel()
video_path = detector.detectObjectsFromVideo(input_file_path=os.path.join(execution_path, "traffic.mp4"), output_file_path=os.path.join(execution_path, "traffic_detected"), frames_per_second=20, log_progress=True)
print(video_path)
rola93 commented 4 years ago

Yep it's a bug. Hope to solve it soon, but checkout this issue

yihanglim commented 4 years ago

wondering how to solve this problem to, I checked the VideoObjectDetection class, there is a line on 1221 to convert BGR to RGB, but not sure why it is not working though.

firmamentone commented 3 years ago

wondering how to solve this problem to, I checked the VideoObjectDetection class, there is a line on 1221 to convert BGR to RGB, but not sure why it is not working though.

Hi

I dumped the image by "cv2.imwrite( )" before and after line 1221. The results are that, before 1221: got the correct image after 1221: got the blue shades image

Besides, the BGR2RGB converting had been used in line 1203 "self.__detector.detectObjectsFromImage( )".

I'm not sure why the BGR2RGB are operated twice (1203 and 1221). I also checked the "detectObjectsFromVideo" of "CustomVideoObjectDetection". (NOT"detectCustomObjectsFromVideo" of "VideoObjectDetection"), the BGR2RGB converting is used only once.