opencv重設圖片尺寸
阿新 • • 發佈:2018-11-09
import cv2 import matplotlib.pylab as plt import numpy as np def show(image): plt.imshow(image) plt.axis('off') plt.show() def imread(image): image = cv2.imread(image) image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) return image image = imread('image.jpg') show(image) print image.shape width = 150 height = 150 image = cv2.resize(image, (width, height), interpolation=cv2.INTER_NEAREST) show(image) image = imread('image.jpg') width = 80 height = int(image.shape[0] * width / image.shape[1]) image = cv2.resize(image, (width, height)) show(image)