dlib downsample_gaussian 在19.24中移除了吗
时间: 2023-12-03 10:05:23 浏览: 48
是的,dlib 19.24 版本中移除了 `downsample_gaussian` 函数。如果需要使用高斯金字塔,可以使用 `pyramid_down` 函数代替。以下是一个使用 `pyramid_down` 函数的示例代码:
```c++
#include <dlib/image_processing.h>
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing/render_face_detections.h>
#include <dlib/image_io.h>
#include <iostream>
#include <math.h>
using namespace dlib;
using namespace std;
//Laplacian金字塔的图像去模糊算法
void deblur_image_pyramid(const matrix<rgb_pixel>& img, matrix<rgb_pixel>& out)
{
//设置金字塔的层数
const int levels = 6;
std::vector<matrix<float>> pyramid(levels), laplacian(levels-1), gaussian(levels-1);
//生成高斯金字塔
pyramid[0] = matrix_cast<float>(img);
for (int i = 1; i < levels; ++i)
pyramid[i] = pyramid_down<2>(pyramid[i-1]);
//生成拉普拉斯金字塔
for (int i = 0; i < levels-1; ++i)
laplacian[i] = pyramid[i] - upsample(pyramid[i+1]);
//调整拉普拉斯金字塔的频率
float sigma = 2;
for (int i = 0; i < levels-1; ++i)
{
//计算该层金字塔对应的sigma
float level_sigma = pow(4.0f, i) * sigma;
//调整金字塔的频率
laplacian[i] = pointwise_multiply(laplacian[i], gaussian_filter(laplacian[i], level_sigma));
}
//重建图像
for (int i = levels-2; i >= 0; --i)
pyramid[i] = laplacian[i] + upsample(pyramid[i+1]);
out = matrix_cast<rgb_pixel>(pyramid[0]);
}
int main()
{
try
{
//加载人脸检测器
frontal_face_detector detector = get_frontal_face_detector();
//加载人脸关键点检测器
shape_predictor sp;
deserialize("shape_predictor_68_face_landmarks.dat") >> sp;
//加载需要处理的图像
matrix<rgb_pixel> img;
load_image(img, "test.jpg");
//检测人脸
std::vector<rectangle> dets = detector(img);
//对每个人脸进行处理
for (auto&& det : dets)
{
//提取人脸关键点
full_object_detection shape = sp(img, det);
//提取人脸区域
matrix<rgb_pixel> face_chip;
extract_image_chip(img, get_face_chip_details(shape,150,0.25), face_chip);
//对人脸区域进行去模糊处理
matrix<rgb_pixel> deblurred_face_chip;
deblur_image_pyramid(face_chip, deblurred_face_chip);
//将去模糊处理后的人脸区域替换原图中的人脸区域
replace_image_chip(img, deblurred_face_chip, get_face_chip_details(shape,150,0.25));
}
//保存处理后的图像
save_jpeg(img, "result.jpg");
}
catch (exception& e)
{
cout << e.what() << endl;
}
}
```
以上代码中,我们使用 `pyramid_down` 函数来生成高斯金字塔,并对金字塔进行处理。需要注意的是,在使用 `pyramid_down` 函数时,需要指定金字塔的下采样倍数,本例中采用的是下采样倍数为 2 的高斯金字塔。