传奇开心果短博文系列
- 系列短博文目录
-
- Python的OpenCV库技术点案例示例短博文系列
- 博文目录
-
- 一、项目目标
- 二、第一个示例代码
- 三、第二个示例代码
- 四、第三个示例代码
- 五、第四个示例代码
- 六、第五个示例代码
- 七、知识点归纳总结
系列短博文目录
Python的OpenCV库技术点案例示例短博文系列
博文目录
一、项目目标
OpenCV图像处理:包括图像滤波、边缘检测、图像变换、颜色空间转换等功能,写示例代码。
二、第一个示例代码
import cv2
import numpy as np
# 读取图像
img = cv2.imread('input.jpg')
# 图像滤波
blur = cv2.GaussianBlur(img, (5, 5), 0)
# 边缘检测
edges = cv2.Canny(img, 100, 200)
# 图像变换
rows, cols = img.shape[:2]
M = cv2.getRotationMatrix2D((cols/2, rows/2), 45, 1)
dst = cv2.warpAffine(img, M, (cols, rows))
# 颜色空间转换
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# 显示结果
cv2.imshow('Original', img)
cv2.imshow('Blurred', blur)
cv2.imshow('Edges', edges)
cv2.imshow('Transformed', dst)
cv2.imshow('HSV', hsv)
cv2.waitKey(0)
cv2.destroyAllWindows()
三、第二个示例代码
import cv2
import numpy as np
# 读取图像
img = cv2.imread('input.jpg')
# 转换为灰度图像
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# 二值化
ret, thresh = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)
# 膨胀和腐蚀
kernel = np.ones((5,5),np.uint8)
dilation =</