博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
opencv: 基本知识(二);
阅读量:4561 次
发布时间:2019-06-08

本文共 2140 字,大约阅读时间需要 7 分钟。

1、Mat与IplImage之间的相互转换;

 

//IplImage—>Mat  //EXAMPLE:  //浅拷贝:  IplImage* pBinary=cvLoadImage("c://temp.jpg",0);  Mat Img;  Img=cvarrToMat(pBinary);  //深拷贝只需要再在Mat里创建一个新的Mat对象,然后进行数据的复制,再用上述的函数进行数据头的复制(浅拷贝):  IplImage* pBinary=cvLoadImage("c://temp.jpg", 0);  Mat ImgTemp;  Img=cvarrToMat(pBinary);  Mat Img = ImgTemp.clone();      //Mat—>IplImage  //EXAMPLE:  //浅拷贝:  Mat Img=imread("1.jpg");  IplImage* pBinary = &IplImage(Img);  //深拷贝只要再加一次复制数据:  IplImage *input = cvCloneImage(pBinary);

2、随机数;

标准库提供了随机函数std::srand,std::rand来生成随机数;

std::srand(unsigned(time(NULL));std::rand();    //生成随机数;

3、矩阵缩放;

opencv的图像缩放函数为cv::resize();

Resizes an image.C++: void resize(InputArray src, OutputArray dst, Size dsize, double fx=0, double fy=0, int interpolation=INTER_LINEAR )Python: cv2.resize(src, dsize[, dst[, fx[, fy[, interpolation]]]]) → dstC: void cvResize(const CvArr* src, CvArr* dst, int interpolation=CV_INTER_LINEAR )Python: cv.Resize(src, dst, interpolation=CV_INTER_LINEAR) → NoneParameters:src – Source image.dst – Destination 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 .dsize – Destination image size. If it is zero, it is computed as:Either dsize or both fx and fy must be non-zero.fx – Scale factor along the horizontal axis. When it is 0, it is computed asfy – Scale factor along the vertical axis. When it is 0, it is computed asinterpolation – Interpolation method:INTER_NEAREST - a nearest-neighbor interpolationINTER_LINEAR - a bilinear interpolation (used by default)INTER_AREA - resampling using pixel area relation. It may be a preferred method for image decimation, as it gives moire’-free results. But when the image is zoomed, it is similar to the INTER_NEAREST method.INTER_CUBIC - a bicubic interpolation over 4x4 pixel neighborhoodINTER_LANCZOS4 - a Lanczos interpolation over 8x8 pixel neighborhood:

使用方法:

cv::Mat(srcIMg,dstImg,dstImg.Size,0,0,cv::INTER_CUBIC);   //fx,fy,将按照dstImg.size与srcImg的比值来进行设置或者cv::Mat(srcImg,dstImg,cv::Size(), 0.5,0.5,cv::INTER_CUBIC);

  

转载于:https://www.cnblogs.com/yinwei-space/p/9101267.html

你可能感兴趣的文章
移走mysql data目录,及常见mysql启动问题
查看>>
模板库Mako的语法
查看>>
快速寻找满足条件的两个数(待完成)
查看>>
##JSP禁用缓存的方式
查看>>
hdu 4720 Naive and Silly Muggles
查看>>
pc端元素拖拽
查看>>
Sublime Text3使用Package Control 报错There Are No Packages Available For Installation
查看>>
判断连通图是否有环(并查集)
查看>>
汽车之家面试题2016
查看>>
POJ-数据结构-优先队列模板
查看>>
【HAOI2006】旅行(并查集暴力)
查看>>
css实现文本超出部分省略号显示
查看>>
留言板
查看>>
vue-router组件状态刷新消失的问题
查看>>
Android UI开发第十四篇——可以移动的悬浮框
查看>>
java8的一些用法
查看>>
Linux入门-ssh scp rsync
查看>>
Criteria查询
查看>>
Heritrix在windows配置步骤
查看>>
(十)Hive分析窗口函数(二) NTILE,ROW_NUMBER,RANK,DENSE_RANK
查看>>