Day1 图像基本操作

# 图像基本操作
import numpy as np
import cv2 as cv     # opencv库

from PIL import Image

# # 为了一直显示图片  在显示图片后加上
# cv.waitKey(0)            # 等待输入  一直显示当前图片
# cv.destroyAllWindows()

# 1.读取图像
img = cv.imread(r".\1.jpg")    # 相对路径

# 2.获取图片属性
sp = img.shape      # 图片的大小  像素 高  宽  通道数

# sp[0] 高
# sp[1] 宽
# sp[2] 通道数

img.size     # 像素点个数

# 3.缩放图片
img_gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
size=img_gray.shape
temping = cv.resize(img_gray, None, fx=0.5, fy=0.5, interpolation=cv.INTER_LINEAR)
cv.imshow('img_gray2', temping)

# 4.旋转图片

# Mat getRotationMatrix2D(Point2f center, double angle, double scale)
# 参数详解:
# Point2f center:表示旋转的中心点
# double angle:表示旋转的角度
# double scale:图像缩放因子

rows, cols = img_gray.shape

M = cv.getRotationMatrix2D((cols/2, rows/2), 90, 1)
dst = cv.warpAffine(img, M, (cols, rows))

cv.imshow('img_gray4', dst)

# 5.仿射变换
rows, cols, ch = img.shape

pts1 = np.float32([[50,50],[200,50],[50,200]])
pts2 = np.float32([[10,100],[200,50],[100,250]])

M = cv.getAffineTransform(pts1,pts2)

dst = cv.warpAffine(img, M, (cols, rows))

cv.imshow('image',dst)


# 6.通道的拆分/合并处理
b,g,r = cv.split(img)
img = cv.merge((b,g,r))
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值