OpenCV-Laplacian和Sobel滤波器的实现
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenCV-Laplacian和Sobel滤波器的实现相关的知识,希望对你有一定的参考价值。
OpenCV Laplacian and Sobel Filters Implementation
#pragma region Laplacian Sobel Filters Mat LaplacianFilter(Mat img, int level){ namedWindow("Original image", CV_WINDOW_AUTOSIZE); imshow("Original image", img); Mat gray,draw,draw2; cvtColor(img, gray, CV_RGB2GRAY); /// Apply Laplace function Laplacian(gray, draw, CV_16S, 3, 1, 0, BORDER_DEFAULT); convertScaleAbs(draw, draw2); imwrite("../../result.jpg", draw2); namedWindow("Result image", CV_WINDOW_AUTOSIZE); imshow("Result image", draw2); waitKey(0); destroyWindow("Result image"); destroyWindow("Original image"); return draw; } Mat SobelFilter(Mat img, int level){ namedWindow("Original image", CV_WINDOW_AUTOSIZE); imshow("Original image", img); Mat grey; cvtColor(img, grey, CV_BGR2GRAY); Mat sobelx; Sobel(grey, sobelx, CV_32F, 1, 0); double minVal, maxVal; minMaxLoc(sobelx, &minVal, &maxVal); //find minimum and maximum intensities cout << "minVal : " << minVal << endl << "maxVal : " << maxVal << endl; Mat draw; sobelx.convertTo(draw, CV_8U, 255.0 / (maxVal - minVal), -minVal * 255.0 / (maxVal - minVal)); imwrite("../../result.jpg", draw); namedWindow("Result image", CV_WINDOW_AUTOSIZE); imshow("Result image", draw); waitKey(0); destroyWindow("Result image"); destroyWindow("Original image"); return draw; } #pragma endregion
以上是关于OpenCV-Laplacian和Sobel滤波器的实现的主要内容,如果未能解决你的问题,请参考以下文章
对于大于 3 x 3 的尺寸,OpenCV 的 Sobel 滤波器的内核系数是多少?
学习 opencv---(11)OpenC 边缘检测:Canny算子,Sobel算子,Laplace算子,Scharr滤波器