将 OpenCV IplImage 或 Mat 复制到 Freeimage FIBITMAP
我需要在 FreeImage (FIBITMAP) 和 OpenCV 格式(IplImage 和/或 Mat)之间交换数据。我很乐意将 FIBITMAP 中的数据获取到 IplImage 或 Mat 中,因为 FreeImage 为您提供了一个函数 FreeImage_GetScanLine ,您可以将 OPenCV imageData ptr 设置为等于。
然而,我被困在如何做相反的事情上,即一旦我有了 OpenCV 图像,如何将其数据获取到 FreeImage 图像中?
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.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是更详细的转换代码。这两个库中有很多图像数据类型,我尝试支持最常见的类型。这假设您传递 cv::Mat 作为源。 FreeImage有左下角的视角!
Here is a more detailed code for the conversion. There are many image data types in either library, I tried supporting most common ones. This assumes you are passing a cv::Mat as the source. FreeImage has the view perspective of lower left!
复制数据指针时您必须小心一点,许多图像格式都有填充以在例如 4 字节边界上开始每个新行。
如果您的图像具有 GetScanLine() 函数,那么制作一个空的 plImage*/cv::Mat 并使用从 GetScanLine() 返回的指针和 cv::MAt 的 .ptr() 成员 memcopy 每一行可能更安全
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.
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
好吧,如果您不介意复制,您可以为 FIBITMAP 创建一个
IplImage*
/cv::Mat
标头,然后复制(使用 opencv 函数) , 像这样:Well, if you don't mind the copy, you can just create an
IplImage*
/cv::Mat
header for the FIBITMAP and then copy (using the opencv function), like this: