引入numpy及cv2库
import cv2
import numpy as np
from matplotlib import pyplot as plt
%matplotlib inline
本文操作的示例图片
建立图片变量:
filename = 'lena.jpg'
## [Load an image from a file]
img = cv2.imread(filename)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.imshow(img)
显示图片大小:
print(img.shape)
这里我们将处理函数封装在类中,例如图片缩放:
class Resize:
def __init__(self, size):
self.size=size
def __call__(self, img):
# 此处插入代码
return cv2.resize(img,self.size)
调用方式如下:
resize=Resize( (600, 600))#此处写入图像想要改向的尺寸
img2=resize(img)
plt.imshow(img2)
图片翻转:
class Flip:
def __init__</