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_img2)

本文介绍了OpenCV的基本操作,包括图像的几何变换、噪声处理、模糊滤波以及亮度和对比度调整。通过实例展示了如何进行盐胡椒噪声消除、高斯模糊以及灰度图像的负片转换,为计算机视觉和深度学习提供了实用的预处理技术。
最低0.47元/天 解锁文章
1475

被折叠的 条评论
为什么被折叠?



