在OpenCv,Python中保存相同图像时无法获得原始图像的相同颜色 [英] Can't get same color of original image when saving same image in OpenCv, Python

查看:97
本文介绍了在OpenCv,Python中保存相同图像时无法获得原始图像的相同颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个代码来旋转图像并保存它们.所以我用OpenCv保存旋转的图像.保存旋转后的图像后,它在图像上变为蓝色.

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.

操作系统:Ubuntu 16.04

OS : Ubuntu 16.04

这是代码:

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!

图片(保存前):

图片(保存后):

推荐答案

我可以解决问题.我必须将图像的颜色转换为RGB颜色.

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

cv2.cvtColor(rotate_img, cv2.COLOR_BGR2RGB)

这是代码:

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

这篇关于在OpenCv,Python中保存相同图像时无法获得原始图像的相同颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆