将OpenCV IplImage或Mat复制到Freeimage FIBITMAP中 [英] Copy OpenCV IplImage or Mat into Freeimage FIBITMAP

查看:209
本文介绍了将OpenCV IplImage或Mat复制到Freeimage FIBITMAP中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在FreeImage(FIBITMAP)和OpenCV格式(IplImage和/或Mat)之间交换数据.我很好地将数据从FIBITMAP导入IplImage或Mat中,因为FreeImage为您提供了功能FreeImage_GetScanLine,您可以将OPenCV imageData ptr设置为等于.

I need to exchange data between FreeImage (FIBITMAP) and OpenCV format (IplImage and/or Mat). I'm fine with getting data from a FIBITMAP into an IplImage or Mat since FreeImage gives you a function FreeImage_GetScanLine which you can set the OPenCV imageData ptr equal to.

但是,我坚持如何做相反的事情,即一旦有了OpenCV映像,如何将其数据转换为FreeImage映像?

However, I'm stuck on how to do the reverse, i.e. once I have an OpenCV image, how do I get its data into a FreeImage image?

推荐答案

复制数据指针时要格外小心,很多图像格式都有填充,以便在4字节边界上每行开始.

You have to be a little careful just copying the data pointer, a lot of image formats have padding to start each new line on eg a 4byte boundary.

如果您的图像具有GetScanLine()函数,那么制作一个空的plImage */cv :: Mat并使用从GetScanLine()返回的指针和cv ::.ptr()成员复制内存的每一行可能更安全.马特

If your image has a GetScanLine() function then it's probably safer to make an empty plImage*/cv::Mat and memcopy each row with the pointer returned from GetScanLine() and the .ptr() member of cv::MAt

cv::Mat &src        
int srcRowBytes = width  * src.elemSize();

for (int ih=0;ih<height;ih++) {
    memcpy(dest.pointer_to_row(ih),src.ptr(ih),srcRowBytes);
}

这篇关于将OpenCV IplImage或Mat复制到Freeimage FIBITMAP中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆