OpenCv 014

1 前备知识

图像在进行几何变换、透视变换等场景时需要插值计算新像素的像素值。

图像处理之三种常见双立方插值算法 - CSDN博客

图像放缩之双立方插值 - CSDN博客

图像放缩之双线性内插值 - CSDN博客

图像处理之Lanczos采样放缩算法 - CSDN博客

(1)INTER_NEAREST最邻近插值

将离新像素所在位置最近的像素像素值赋值给新像素。计算亮最小。

(2)双线性插值

x、y方向临近像素取乘以相应权重并相加赋值给i新的像素值。

(3)双立方插值

精度更高,计算量最大,取附近十六个点加权取像素值。

(4)INTER_LANCZOS4

附近像素及原像素加权取值。

2 所用到的主要OpenCv API

/** @brief 对一副图像指定x,y方向上的缩放比例进行缩放。

@code
// explicitly specify dsize=dst.size(); fx and fy will be computed from that.
resize(src, dst, dst.size(), 0, 0, interpolation);
@endcode
If you want to decimate the image by factor of 2 in each direction, you can call the function this
way:
@code
// specify fx and fy and let the function compute the destination image size.
resize(src, dst, Size(), 0.5, 0.5, interpolation);
@endcode
To shrink an image, it will generally look best with #INTER_AREA interpolation, whereas to
enlarge an image, it will generally look best with c#INTER_CUBIC (slow) or #INTER_LINEAR
(faster but still looks OK).

@param src input image.
@param dst output image; it has the size dsize (when it is non-zero) or the size computed from
src.size(), fx, and fy; the type of dst is the same as of src.
@param dsize output image size; if it equals zero, it is computed as:
\f[\texttt{dsize = Size(round(fx*src.cols), round(fy*src.rows))}\f]
Either dsize or both fx and fy must be non-zero.
@param fx scale factor along the horizontal axis; when it equals 0, it is computed as
\f[\texttt{(double)dsize.width/src.cols}\f]
@param fy scale factor along the vertical axis; when it equals 0, it is computed as
\f[\texttt{(double)dsize.height/src.rows}\f]
@param interpolation interpolation method, see #InterpolationFlags

@sa warpAffine, warpPerspective, remap
*/

1CV_EXPORTS_W void resize( InputArray src, OutputArray dst, 2 Size dsize, double fx = 0, double fy = 0, 3 int interpolation = INTER_LINEAR );

3 程序代码

1#include"opencv2\opencv.hpp" 2#include<iostream> 3 4using namespace std; 5using namespace cv; 6 7int main(int argc, char** argv) 8{ 9 Mat src = imread("G:\\CVworkstudy\\program_wwx\\研习社140课时\\ZhaiZhigang140\\colormap.png"); 10 if (src.empty()) 11 { 12 printf("Could not load image...\n"); 13 return -1; 14 } 15 imshow("srcImg", src); 16 Mat dst = Mat::zeros(src.size(), src.type()); 17 double fx = 0, fy = 0; 18 int height = src.rows; 19 int width = src.cols; 20 //最邻近插值 21 resize(src, dst, Size(0, 0), 0.5, 0.5, INTER_NEAREST);//如果Size(0,0),则图像大小为Size(width*fx height*fy) 22 imshow("NEAREST", dst); 23 //双线性插值 24 resize(src, dst, Size(width * 2, height * 2), fx, fy, INTER_LINEAR); 25 imshow("LineNear", dst); 26 //双立方插值 27 resize(src, dst, Size(width * 2, height * 2), fx, fy, INTER_CUBIC); 28 imshow("CUBIC", dst); 29 //LANCZOS插值 30 resize(src, dst, Size(width * 2, height * 2), fx, fy, INTER_LANCZOS4); 31 imshow("LANCZOS", dst); 32 33 waitKey(0); 34 return 0; 35}

4 运行结果

5 扩展及注意事项

null

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )