3.1 原理介绍
Laplacian(拉普拉斯)算子是一种二阶导数算子,其具有旋转不变性,可以满足不同方向的图像边缘锐化(边缘检测)的要求。通常情况下,其算子的系数之和需要为零。例 如,一个3×3大小的Laplacian算子如图所示。

Laplacian算子类似二阶Sobel导数,需要计算两个方向的梯度值。例如,在图中:

检测值 =(P2+P4+P6+P8)-4*P5
需要注意,在上述图像中,计算结果的值可能为正数,也可能为负数。所以,需要对计算结果取绝对值,以保证后续运算和显示都是正确的。
该函数分别对x、y方向进行二次求导,具体为:

式中,dst代表目标图像,src代表原始图像。
3.2 函数语法
在OpenCV内使用函数cv2.Laplacian()实现Laplacian算子的计算,该函数的语法格式为:
dst=cv2.Laplacian(src,ddepth[,ksize[,scale[,delta[,borderType]]]])
式中:
● dst代表目标图像。
● src代表原始图像。
● ddepth代表目标图像的深度。
● ksize代表用于计算二阶导数的核尺寸大小。该值必须是正的奇数。当ksize的值为1时,Laplacian算子计算时采用的 3×3的核如上所示。
● scale代表计算Laplacian值的缩放比例因子,该参数是可选的。默认情况下,该值为 1,表示不进行缩放。
● delta代表加到目标图像上的可选值,默认为0。
● borderType代表边界样式。
通常情况下,在使用Laplacian算子时,对于参数ksize、scale、delta和borderType,直接采用其默认值即可。因此,函数cv2.boxFilter()的常用形式为:
dst=cv2.Laplacian(src,ddepth)
3.3 程序示例
import cv2 as cv
def cv_show(name, img):
cv.imshow(name, img)
cv.waitKey(0)
cv.destroyAllWindows()
# laplacian算子可对灰度图像和彩色图像使用
img = cv.imread('D:\\qipan.jpg')
if img is None:
print('Failed to read the image')
lap = cv.Laplacian(img, cv.CV_64F)
img1 = cv.convertScaleAbs(lap)
cv_show('lap', img1)
原图如下:

Laplacian算子:

由上图可知,Laplacian算子比Sobel算子、Scharr算子语法更为简单,不需要在x,y两个方向分别进行检测,检测效果与Sobel算子、Scharr算子相差不大。
OpenCV: 开源计算机视觉库
最近提交(Master分支:30 天前 )
75598e53
Fix QRCodeDetector::detectAndDecode crash #27877
### Pull Request Readiness Checklist
Fix #27807
The problem is that when we find closest points from hull, we can get same closest point for several different points
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
14 小时前
b6447542
Fix invalid memory access in USAC #27865
### Pull Request Readiness Checklist
Fix #27863
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
2 天前
所有评论(0)