首页 > 代码库 > OpenCV Tutorials —— Laplace Operator
OpenCV Tutorials —— Laplace Operator
发掘图像边界 —— 一阶导数顶点不好求,可用二阶导数过零点来代替
Getting the first derivative of the intensity, we observed that an edge is characterized by a maximum, as it can be seen in the figure:
You can observe that the second derivative is zero! So, we can also use this criterion to attempt to detect edges in an image.
- The Laplacian operator is defined by:
Laplacian( src_gray, dst, ddepth, kernel_size, scale, delta, BORDER_DEFAULT );
- src_gray: The input image.
- dst: Destination (output) image
- ddepth: Depth of the destination image. Since our input is CV_8U we define ddepth = CV_16S to avoid overflow
- kernel_size: The kernel size of the Sobel operator to be applied internally. We use 3 in this example.
- scale, delta and BORDER_DEFAULT: We leave them as default values.
convertScaleAbs( dst, abs_dst );
Convert the output from the Laplacian operator to a CV_8U image
Code
#include "stdafx.h"#include "opencv2/imgproc/imgproc.hpp"#include "opencv2/highgui/highgui.hpp"#include <stdlib.h>#include <stdio.h>using namespace cv;/** @function main */int main( int argc, char** argv ){ Mat src, src_gray, dst; int kernel_size = 3; int scale = 1; int delta = 0; int ddepth = CV_16S; char* window_name = "Laplace Demo"; int c; /// Load an image src = http://www.mamicode.com/imread("img2.jpg"); if( !src.data ) { return -1; } /// Remove noise by blurring with a Gaussian filter GaussianBlur( src, src, Size(3,3), 0, 0, BORDER_DEFAULT ); /// Convert the image to grayscale cvtColor( src, src_gray, CV_RGB2GRAY ); /// Create window namedWindow( window_name, CV_WINDOW_AUTOSIZE ); /// Apply Laplace function Mat abs_dst; Laplacian( src_gray, dst, ddepth, kernel_size, scale, delta, BORDER_DEFAULT ); convertScaleAbs( dst, abs_dst ); /// Show what you got imshow( window_name, abs_dst ); waitKey(0); return 0;}
OpenCV Tutorials —— Laplace Operator
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。