OpenCV双边滤波测试
程序员文章站
2022-07-14 23:34:46
...
OpenCV双边滤波测试
测试代码
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
#define dbg(fmt,...) do{printf("[DEBUG %s:%d] " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__);}while(0)
#define info(fmt,...) do{printf("[INFO %s:%d] " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__);}while(0)
#define warn(fmt,...) do{printf("[WARN %s:%d] " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__);}while(0)
#define err(fmt,...) do{printf("[ERROR %s:%d] " fmt "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__);}while(0)
#define IMG_FILE "001.png"
static void _TrackbarCallback (int pos, void* userdata)
{
int* bChanged = (int*)userdata;
*bChanged = 1;
}
int BilateralFilterTest()
{
Mat img0, img;
const char* winName = "BilateralFilterTest";
const char* tbNameD = "d";
const char* tbNameSigmaColor = "sigmaColor";
const char* tbNameSigmaSpace = "sigmaSpace";
int tbValueD = 3;
int tbValueSigmaColor = 0;
int tbValueSigmaSpace = 0;
int tbChanged = 1;
img0 = imread(IMG_FILE);
if (img0.empty()) {
err("imread %s failed", IMG_FILE);
goto _exit;
}
imshow("原图", img0);
namedWindow(winName);
createTrackbar(tbNameD, winName, &tbValueD, 30, _TrackbarCallback, &tbChanged);
createTrackbar(tbNameSigmaColor, winName, &tbValueSigmaColor, 1000, _TrackbarCallback, &tbChanged);
createTrackbar(tbNameSigmaSpace, winName, &tbValueSigmaSpace, 1000, _TrackbarCallback, &tbChanged);
img = img0.clone();
imshow(winName, img);
while (1) {
if (tbChanged) {
int d = tbValueD / 2 * 2 + 1;
double sigmaColor = tbValueSigmaColor / 10.0;
double sigmaSpace = tbValueSigmaSpace / 10.0;
dbg("bilateralFilter d:%d sigmaColor:%f sigmaSpace:%f", d, sigmaColor, sigmaSpace);
bilateralFilter(img0, img, d, sigmaColor, sigmaSpace);
imshow(winName, img);
tbChanged = 0;
}
if (waitKey(100) > 0)
break;
}
_exit:
destroyAllWindows();
dbg("例程退出");
getchar();
return 0;
}
运行效果
上一篇: RocketMQ事务消息实现分布式事务
下一篇: 在OpenCV里实现双边滤波
推荐阅读
-
解决python测试opencv时imread导致的错误问题
-
VS2019配置OpenCV4.1.0详细教程与测试代码(推荐)
-
Java+opencv3.2.0之scharr滤波器
-
Java OpenCV图像处理之自定义图像滤波算子
-
python+opencv实现高斯平滑滤波
-
Java OpenCV图像处理之自定义图像滤波算子
-
基于opencv下对视频的灰度变换,高斯滤波,canny边缘检测处理,同窗体显示并保存
-
opencv-12-高斯滤波-双边滤波(附C++代码实现)
-
C++实现OpenCV方框滤波的代码
-
python-opencv 中值滤波{cv2.medianBlur(src, ksize)}的用法