opencv mat和CImage之间的转换 [英] Conversion between opencv mat and CImage
问题描述
我正在寻找一种将opencv Mat变量中存储的图像转换为CImage对象的有效方法(CBitmap也可以).高效是指快速和短拼". 我的扩展搜索导致查找代码,该代码手动将位图标题和数据写入对象,这是我想避免的,因为我不太了解那里发生了什么.更糟糕的是,它看起来已经过时了,并产生了运行时错误... (我相信我在这里获得了它: http://howto-code-it.blogspot.com/2011/05/how-to-convert-iplimage-to-hbitmap.html )
I am looking for an efficient way for converting an image stored in opencv Mat variable to a CImage object (CBitmap would be good as well). By efficient I mean both fast, and 'short-spelled'. my extended search resulted with finding code which is manually writing bitmap headers and data to the object, which i'd like to avoid, as i do not quite understand what is going on there. to make things worse it looks a little bit deprecated and produces runtime errors... (i believe i obtained it here: http://howto-code-it.blogspot.com/2011/05/how-to-convert-iplimage-to-hbitmap.html)
就目前而言,我只是逐个完成像素操作,虽然不太明智(尽管我需要使其工作),但现在是时候提高性能了;)
as for now i'm just coppying pixels one by one which is not too wise (though i needed to make it work) and it is time to improve performance;)
如果有人可以通过其他方式提出转换,也将不胜感激.
if anyone could come up with conversion in the other way it would also be appreciated.
推荐答案
要复制数据,您不需要逐像素进行处理.一种方法是(及其标题):
To copy data, you don't need to do it pixel by pixel. One way is (and its header):
CImage* m_pImg;
cv::Size m_sizeShow;
cv::Mat m_matCVImg;
BITMAPINFO bitInfo;
...
StretchDIBits(m_pImg->GetDC(), 0, 0,
m_sizeShow.width, m_sizeShow.height, 0, 0,
m_sizeShow.width, m_sizeShow.height,
matImgTmp.data, &bitInfo, DIB_RGB_COLORS, SRCCOPY);
查看 http://kvy.com.ua/opencv-image-to-mfc-image-in-msvc-project/的逐步说明.
这篇关于opencv mat和CImage之间的转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!