opencv对图像反转保存

import cv2
# opencv读取图像
img = cv2.imread('./1.jpg', 1)
cv2.imshow('img', img)
img_shape = img.shape  # 图像大小(565, 650, 3)
print(img_shape)
h = img_shape[0]
w = img_shape[1]
# 彩色图像转换为灰度图像(3通道变为1通道)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
print(gray.shape)
# 最大图像灰度值减去原图像,即可得到反转的图像
dst = 255 - gray
cv2.imshow('dst', dst)
cv2.imwrite("ok.jpg",dst)
cv2.waitKey(0)

输入:
在这里插入图片描述
输出:
在这里插入图片描述

原创文章 68 获赞 134 访问量 5万+

猜你喜欢

转载自blog.csdn.net/liupeng19970119/article/details/105604540