OpenCV基本操作
引入
import cv2 as cv
import numpy as np
import random
src = cv.imread("E:\DIP\imag\l_hires.jpg")
几何变换
#图像裁剪
print(src.shape)
#(2318,1084,3)
new_src = src[200:600,300:700]
cv.imwrite('new_src.jpg',new_src)
# 图像尺寸变换
img = cv.imread('new_src.jpg')
print(img.shape)
#(600,600,3)
new_img = cv.resize(img,(300,300),interpolation = cv.INTER_AREA)
cv.imwrite('new_img1.jpg',new_img)
print(new_img.shape)
new_img2 = cv.resize(img, None, fx=0.5, fy=0.5, interpolation = cv.INTER_AREA)
print(new_img2.shape)
#图像的宽对应的是列数,高对应的是行数
#(300,300,3)
cv.imwrite('new_img2.jpg',new_im