将 GdiPlus::Bitmap 转换为 OpenCV IplImage
我有一个 24bpp GdiPlus::Bitmap
,我需要将其转换为 IplImage
(opencv)。 有谁知道如何做到这一点?
I have a 24bpp GdiPlus::Bitmap
that i need to convert into IplImage
(opencv).
Does anyone know how can this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下是您可以如何做到这一点。
1.) 创建一个新的目标 IplImage 对象,其尺寸为源图像 (GdiPlus::Bitmap)
2.) 使用 lockbits 获取源图像的像素数据句柄
3.) 将源像素数据复制到目标图像数据
4.) 源图像的 UnlockBits
Here is how you can do it.
1.) Create a new target IplImage object with the dimensions of Source image (GdiPlus::Bitmap)
2.) Get the pixeldata handle of Source image using lockbits
3.) Copy the source pixeldata to target imagedata
4.) UnlockBits of source image
这是您问题的答案,唯一的区别是 BitMap 转换为 Mat:将 Bitmap 转换为 Mat
Here is an answer for your issue with the only difference, that BitMap converts to Mat: Convert Bitmap to Mat
困难在于 Gdiplus::Bitmap 理论上支持许多奇异的像素格式,因此总的来说,转换会很冗长。但基本情况如下:
The difficulty is that Gdiplus::Bitmap supports lots of exotic pixel formats in theory, so in full generality the conversion would be verbose. However, the basic case is as follows: