1

I have Numpy list of 1000 RGB images (1000, 96, 96, 3). I have used openCV to create a mp4 video out of these images. my road is brown and car is red but after I create the video they turned blue. Could you please tell me how could I avoid this problem?

My code:

img_array = []
for img in brown_dataset:
    img_array.append(img)

size = (96,96)

out = cv2.VideoWriter('project_brown.mp4',cv2.VideoWriter_fourcc(*'DIVX'),15, size)

for i in range(len(img_array)):
    out.write(img_array[i])
out.release()

Before video:

enter image description here

After video:

enter image description here

Community
  • 1
  • 1
Mshz
  • 17
  • 4

1 Answers1

1

As mentioned in the comments , OpenCV uses BGR format by default, where your input dataset is RGB.

Here is one way to fix it

img_array = []
for img in brown_dataset:
    img_array.append(img)

size = (96,96)

out = cv2.VideoWriter('project_brown.mp4',cv2.VideoWriter_fourcc(*'DIVX'),15, size)

for i in range(len(img_array)):
    rgb_img = cv2.cvtColor(img_array[i], cv2.COLOR_RGB2BGR)
    out.write(rgb_img)
out.release()
velociraptor11
  • 576
  • 1
  • 5
  • 10