OpenCV 之 Mat IplImage 读取本地图片
发布日期:2021-11-13 20:28:00 浏览次数:9 分类:技术文章

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

Mat imread 与 IplImage cvLoadImage区别  

2013-03-05 10:14:39|  分类: |举报|字号 

Q : I have two options to load images: 

1- Mat and Imread

2- IplImage and CvLoadImage    
Which one is better to use?

A : They are the two different interfaces (Mat/imread for 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++)

cv::Mat image = imread("path/to/myimage.jpg")if(image.empty())    return;cv::imshow("Image", image);cv::Mat bw = image > 128; // threshold imagecv::Mat crop = image(cv::Rect(0, 0, 100, 100)); // a 100px x 100px cropcrop= 0; // set image to 0cv::waitKey();
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

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.
另:
1.imread是C++接口,cvloadimage是c接口。2.imread的定义在highgui.hpp中,cvloadimage的定义在highgui-c.h中,而highgui.hpp和highgui-c.h都包含在highgui.h中,所以我们在写程序是只要包含了highgui.h,那么我们就可以用两个接口。
 

转载地址:https://blog.csdn.net/lphbtm/article/details/51037775 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:德州仪器(TI)3D机器视觉参考设计
下一篇:OpenCV300 CMake生成工程项目过程中的问题

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月09日 18时14分47秒