opencv python 学习笔记(一) 图像的基本处理

1.读取图片
这里要注意的是路径不能出现中文

import cv2

img=cv2.imread(r'D:\tupian\build.jpg',1)

cv2.imshow('img',img)

cv2.waitKey(0)

在这里插入图片描述
2.划线

for i in range(1,100):
    img[i,i]=(255,0,0)

cv2.imshow('img1',img)
cv2.waitKey(0)

在这里插入图片描述

3.图片缩放

dst=cv2.resize(img,(0,0),fx=0.4,fy=0.4)

cv2.imshow("dst",dst)

cv2.waitKey(0)

在这里插入图片描述
4.剪切

dst1=img[10:500,10:300]

cv2.imshow("剪切",dst1)

cv2.waitKey(0)

在这里插入图片描述
5.旋转

shape=img.shape

print(shape)

h=shape[0]

w=shape[1]

mxz=cv2.getRotationMatrix2D((w*0.5,h*0.5),45,0.5)

xz=cv2.warpAffine(img,mxz,(w,h))

cv2.imshow('xz',xz)

cv2.waitKey(0)

在这里插入图片描述
6.灰度处理

hui=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

cv2.imshow('hui',hui)

cv2.waitKey(0)

在这里插入图片描述
以上是图片的基本处理,就不过多介绍,直接看代码就行。

猜你喜欢

转载自blog.csdn.net/Lightismore/article/details/124270889