Opencv影象線性濾波-滾動條
阿新 • • 發佈:2019-01-05
#include<iostream> #include<opencv2/opencv.hpp> using namespace std; using namespace cv; Mat srcImage; Mat dstBoxFilter, dstBlur, dstGaussianBlur; int g_BoxFilterValue = 1, g_BlurValue = 1, g_GaussianBlurValue = 1; const int g_nMaxAlphaValue = 100; //有滾動條事件時,可以進入回撥函式 void on_Trackbar(int, void *) { boxFilter(srcImage, dstBoxFilter, -1, Size(g_BoxFilterValue + 1, g_BoxFilterValue + 1)); blur(srcImage, dstBlur, Size(g_BlurValue + 1, g_BlurValue + 1)); //高斯濾波必須是奇數值 GaussianBlur(srcImage, dstGaussianBlur, Size(2 * g_GaussianBlurValue + 1, 2 * g_GaussianBlurValue + 1), 0, 0); imshow("方框濾波", dstBoxFilter); imshow("均值濾波", dstBlur); imshow("高斯濾波", dstGaussianBlur); } int main() { srcImage = imread("牛吃草.jpg"); dstBoxFilter.create(srcImage.size(), srcImage.type()); dstBlur.create(srcImage.size(), srcImage.type()); dstGaussianBlur.create(srcImage.size(), srcImage.type()); g_BoxFilterValue = 0; g_BlurValue = 0; g_GaussianBlurValue = 0; namedWindow("方框濾波"); createTrackbar("Value", "方框濾波", &g_BoxFilterValue, g_nMaxAlphaValue, on_Trackbar); on_Trackbar(g_BoxFilterValue, 0); namedWindow("均值濾波"); createTrackbar("Value", "均值濾波", &g_BlurValue, g_nMaxAlphaValue, on_Trackbar); on_Trackbar(g_BlurValue, 0); namedWindow("高斯濾波"); createTrackbar("Value", "高斯濾波", &g_GaussianBlurValue, g_nMaxAlphaValue, on_Trackbar); on_Trackbar(g_GaussianBlurValue, 0); waitKey(0); return 0; }