opencv - 我应该在调整大小之前使用 PyrDown 以获得更好的结果吗?
问题描述
使用 OpenCvSharp 包装器,我一直在使用这个函数来调整图像大小(保持纵横比)
public static void Resize_PreserveAspectRatio(this Mat mat, Mat dst, int length, InterpolationFlags st = InterpolationFlags.Cubic, bool changeMaxLength = true)
{
double w = mat.Width;
double h = mat.Height;
double div = changeMaxLength ? Math.Max(w, h) : Math.Min(w, h);
double w1 = (w / div) * length;
double h1 = (h / div) * length;
Cv2.Resize(mat, dst, new Size(w1, h1), 0d, 0d, st);
}
将宽度为 1920 像素的图像调整为 200 像素的大小时,我意识到即使使用三次插值,结果看起来也很糟糕。我试过这段代码不直接使用 OpenCV 调整大小,而是先使用 PyrDown:
public static void Resize_PreserveAspectRatio(this Mat mat, Mat dst, int length, InterpolationFlags st = InterpolationFlags.Cubic, bool changeMaxLength = true)
{
double w = mat.Width;
double h = mat.Height;
double len2x = length * 2d;
double div = changeMaxLength ? Math.Max(w, h) : Math.Min(w, h);
if (div > len2x)
{
using (Mat mat1 = mat.Clone())
{
while (div > len2x)
{
Cv2.PyrDown(mat1, mat1);
w = mat1.Width;
h = mat1.Height;
div = changeMaxLength ? Math.Max(w, h) : Math.Min(w, h);
}
double w1 = (w / div) * length;
double h1 = (h / div) * length;
Cv2.Resize(mat1, dst, new Size(w1, h1), 0d, 0d, st);
}
}
else
{
double w1 = (w / div) * length;
double h1 = (h / div) * length;
Cv2.Resize(mat, dst, new Size(w1, h1), 0d, 0d, st);
}
}
结果是:
这是正常的,还是 OpenCV Resize 函数(或包装器)有问题?
编辑:
我实际上要问的是,这些结果正常吗?
编辑2
解决方案
推荐阅读
- scenekit - 在 Scenekit 中,摩擦系数如何在一对材料之间应用
- facebook-graph-api - 我是否需要“公共页面内容”权限才能阅读页面帖子?
- sql - 用一个条件计算分区(/不计算 NULL 值)
- android - Android忽略runOnUiThread中语言文件中的字符串
- codeigniter - Google Recatpcha v2 Invisible 根本不工作说缺少输入响应
- tableview - tableView didset 不重新加载
- node.js - 用另一个 pug 文件替换字符串并将动态数据传递给该文件
- r - 在 R sf 的分组列上创建新几何
- python - Discord.py - 如何接收和发送消息到特定频道?
- php - 尝试一些自定义数组差异,如 PHP 中的方法