Mat imread 与 IplImage cvLoadImage区别
2015-06-03 22:31
274 查看
Mat imread 与 IplImage cvLoadImage区别
原文地址 http://blog.163.com/yuyang_tech/blog/static/21605008320132510104620/
Q : I have two options to load images: 来源1
1- Mat and Imread
2- IplImage and CvLoadImage
Which one is better to use?
A : They are the two different interfaces (
safer and easier to use. It automatically handles memory for you, and allows you to write less code for the same task. The OpenCV guys advocate for the usage of C++, unless some very specific project requirements force you to C.
Example (C++)
To create a new copy of data, use Mat::copyTo, or Mat::clone();
And the C interface
原文地址 http://blog.163.com/yuyang_tech/blog/static/21605008320132510104620/
Q : I have two options to load images: 来源1
1- Mat and Imread
2- IplImage and CvLoadImage
Which one is better to use?
A : They are the two different interfaces (
Mat/
imreadfor C++ and Ipl... and Cv.. for C interface). The C++ interface is nicer,
safer and easier to use. It automatically handles memory for you, and allows you to write less code for the same task. The OpenCV guys advocate for the usage of C++, unless some very specific project requirements force you to C.
Example (C++)
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;">cv::Mat image = imread("path/to/myimage.jpg") if(image.empty()) return; cv::imshow("Image", image); cv::Mat bw = image > 128; // threshold image cv::Mat crop = image(cv::Rect(0, 0, 100, 100)); // a 100px x 100px crop crop= 0; // set image to 0 cv::waitKey();</p>
Note that if not stated otherwise, all matrix assignments reference the same data. In the example above, the crop matrix points to image, and setting it to zero will set that specific part of the image to 0.
To create a new copy of data, use Mat::copyTo, or Mat::clone();
And the C interface
<p style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-bottom: 0px;">IplImage* pImg = CvLoadImage("path/to/myimage.jpg"); if(pImg == NULL) return; // ... big bloat to do the same operations with IplImage CvShowImage("Image", pImg); cvWaitKey(); CvReleaseImage(&pImg); // Do not forget to release memory.</p>
另:来源2
1.imread是C++接口,cvloadimage是c接口。 2.imread的定义在highgui.hpp中,cvloadimage的定义在highgui-c.h中,而highgui.hpp和highgui-c.h都包含在highgui.h中,所以我们在写程序是只要包含了highgui.h,那么我们就可以用两个接口。
相关文章推荐
- 苹果开发 笔记(34)UICollectionView
- ubuntu 下 pm2 error /usr/bin/env: node: No such file or directory解决方案
- 排版系统Latex傻瓜方式使用(论文排版)
- 页面Http状态查询工具说明
- 使用easyui执行post后不会提交kindeditor对应的textarea中新增的内容。只会显示默认内容解决办法
- OJ刷题---ASCII码排序
- Kmeans在MapReduce中的实现
- ASP.NET MVC与WebForm区别
- 备忘
- STM32时钟初始化研究
- volatile
- Linux下安装Tomcat服务器和部署Web应用
- ios学习路线
- 【HDU】5256 序列变换(最长上升子序列变形)
- 【leetcode 两个链表的交集点】Intersection of Two Linked Lists
- 用SecureCRT在windows和CentOS间上传下载文件
- 5.2-5
- 第一天
- POJ 2386 Lake Counting
- Android通过Wifi来调试