opencv

使用opencv3处理图像

#模糊算子

#高斯模糊函数 (5, 5)表示高斯矩阵的长与宽都是5,标准差取0
cv2.GaussianBlur(img,(5,5),0)
#中值滤波,相当于将blurKsize= 3 相当9个值进行排序,取中值作为当前值return img
cv2.medianBlur(img,blurKsize)

#边缘检测算子
cv2.Laplacian(src_img,cv2.CV_8U,dst_img,ksize)
#卷积操作
cv.filter2D(src, ddepth, kernel[, dst[, anchor[, delta[, borderType]]]]	)

#for example 
import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
img = cv.imread('opencv_logo.png')
kernel = np.ones((5,5),np.float32)/25
#-1 mean same depth
dst = cv.filter2D(img,-1,kernel)
plt.subplot(121),plt.imshow(img),plt.title('Original')
plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(dst),plt.title('Averaging')
plt.xticks([]), plt.yticks([])
plt.show()

#canny算子
edges	=	cv.Canny(	image, threshold1, threshold2[, edges[, apertureSize[, L2gradient]]]	)

[详见链接](https://docs.opencv.org/master/da/d22/tutorial_py_canny.html)

#轮廓检测 first one is source image, second is contour retrieval mode, third is contour approximation method
contours, hierarchy	=	cv.findContours(	image, mode, method[, contours[, hierarchy[, offset]]]	)
#画出轮廓  Its first argument is source image, second argument is the contours which should be passed as a Python list, third argument is index of contours (useful when drawing individual contour. To draw all contours, pass -1) and remaining arguments are color, thickness etc
image	=	cv.drawContours(	image, contours, contourIdx, color[, thickness[, lineType[, hierarchy[, maxLevel[, offset]]]]]	)
[详见链接](https://docs.opencv.org/master/d4/d73/tutorial_py_contours_begin.html)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值