opencv多张图片显示

import numpy as np
import cv2

def cv_norm_proc(img): # cv_norm_proc函数将图片归一化 [-1,1]
    img_rgb = (img / 255. - 0.5) * 2
    return img_rgb

def cv_inv_proc(img): # cv_inv_proc函数将读取图片时归一化的图片还原成图像
    img_rgb = (img + 1.) * 127.5
    return img_rgb.astype(np.float32)

def get_write_picture(x_image, y_image, fake_y, fake_x_, fake_x, fake_y_):
    x_image = cv_inv_proc(x_image)
    y_image = cv_inv_proc(y_image)
    fake_y = cv_inv_proc(fake_y)
    fake_x_ = cv_inv_proc(fake_x_)
    fake_x = cv_inv_proc(fake_x)
    fake_y_ = cv_inv_proc(fake_y_)
    row1 = np.concatenate((x_image, fake_y, fake_x_), axis=1) # 第一行
    row2 = np.concatenate((y_image, fake_x, fake_y_), axis=1) # 第二行
    output = np.concatenate((row1, row2), axis=0)
    return output

if __name__ == '__main__':
    img_path = r"n02381460_140.jpg"
    img = cv2.imread(img_path)

    img_norm = cv_norm_proc(img)

    # img_rgb = cv_inv_proc(img_norm).astype(np.uint8)
    img_rgb = cv_inv_proc(img_norm)

    cv2.imwrite("img.jpg",img_rgb)

    cv2.imshow('img', img_rgb)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

 

你可能感兴趣的:(opencv)