2

I have written a code to rotate images and save them. So I used OpenCv to save rotated image. After save the rotated image, It gets blue on the image.

OS : Ubuntu 16.04

This is the code :

from scipy.ndimage import rotate
from scipy.misc import imread, imshow
import cv2
count = 0
while True:
    if count<230:
    filename = 'frame'+str(count)+'.jpg'
    print(filename)
    img = imread(filename)

    rotate_img = rotate(img, 90)
    cv2.imwrite(filename,rotate_img)
    count = count + 1
        continue
    else :
    break

Why color change like this? What should I need to do? Any help would be appreciated! Thank you in Advanced!

Image(Before saved) :

enter image description here

Image(After saved) :

enter image description here

Sarasa Gunawardhana
  • 1,099
  • 3
  • 14
  • 34

2 Answers2

2

I could solve the problem. I have to convert color of image into RGB color.

cv2.cvtColor(rotate_img, cv2.COLOR_BGR2RGB)

Here is the code :

from scipy.ndimage import rotate
from scipy.misc import imread, imshow
import cv2
count = 0
while True:
    if count<230:
    filename = 'frame'+str(count)+'.jpg'
    print(filename)
    img = imread(filename)

    rotate_img = rotate(img, 90)
    #convert color of image before saving
    rgbImg = cv2.cvtColor(rotate_img, cv2.COLOR_BGR2RGB)
    cv2.imwrite(filename,rgbImg)
    count = count + 1
        continue
    else :
    break
Sarasa Gunawardhana
  • 1,099
  • 3
  • 14
  • 34
2

The problem here is that you're using scipy's imread that creates RGB images and OpenCV imwrite that writes images assuming they are BGR.

Invert the first and third channels of your images.

Sunreef
  • 4,452
  • 21
  • 33