如何在目录中使用Python存储OpenCV生成的图像?

时间:2016-10-13 08:47:02

标签: python image python-2.7 opencv numpy

我已经尝试了一个python脚本,它将图像缩放了2倍并且工作正常,但问题是如何将这个结果图像存储在我的磁盘中,以便我可以比较之前和之后的结果。

import cv2
import numpy as np

img = cv2.imread('input.jpg')

res = cv2.resize(img,None,fx=2, fy=2, interpolation = cv2.INTER_CUBIC)

结果存储在res变量中,但应将其创建为新图像。怎么样?

我想要的输出应该是result.jpg

印刷时我得到了什么

>>> res
array([[[ 39,  43,  44],
        [ 40,  44,  44],
        [ 41,  45,  46],
        ..., 
        [ 54,  52,  52],
        [ 52,  50,  50],
        [ 51,  49,  49]],

       [[ 38,  42,  44],
        [ 39,  43,  44],
        [ 41,  45,  46],
        ..., 
        [ 55,  53,  53],
        [ 54,  52,  52],
        [ 53,  51,  51]],

       [[ 37,  40,  43],
        [ 38,  41,  44],
        [ 40,  43,  46],
        ..., 
        [ 58,  56,  55],
        [ 56,  54,  54],
        [ 56,  53,  53]],

       ..., 
       [[ 52, 135,  94],
        [ 54, 137,  95],
        [ 59, 141,  99],
        ..., 
        [ 66, 139, 101],
        [ 62, 135,  96],
        [ 60, 133,  94]],

       [[ 47, 131,  89],
        [ 49, 133,  91],
        [ 55, 138,  96],
        ..., 
        [ 56, 129,  91],
        [ 54, 127,  89],
        [ 54, 127,  88]],

       [[ 44, 128,  86],
        [ 47, 130,  88],
        [ 53, 136,  94],
        ..., 
        [ 50, 123,  85],
        [ 50, 123,  85],
        [ 50, 123,  85]]], dtype=uint8)

1 个答案:

答案 0 :(得分:1)

您可以使用imwrite功能。

您可以找到此功能的说明here