在c ++/cx中将SoftwareBitmap或WriteableBitmap转换为cv :: Mat [英] Converting a SoftwareBitmap or WriteableBitmap to cv::Mat in c++/cx
问题描述
我试图在c ++/cx Microsoft通用应用程序中将WriteableBitmap转换为cv :: Mat.但是,当我尝试使用创建的Mat进行处理时,出现以下错误:
I tried to convert a WriteableBitmap to a cv::Mat in a c++/cx Microsoft universial App. But when I try to progress with the created Mat, I get the following error:
这是我的代码:
void App1::MainPage::processImage(SoftwareBitmap^ bitmap)
{
WriteableBitmap^ wb = ref new WriteableBitmap(bitmap->PixelWidth, bitmap->PixelHeight);
bitmap->CopyToBuffer(wb->PixelBuffer);
Mat img_image(wb->PixelHeight, wb->PixelWidth, CV_8UC3,(void*)wb->PixelBuffer);
//next step results in error
cvtColor(img_image, img_image, CV_BGR2BGRA);
...
}
所以我的最后一个问题是: 如何将SoftwareBitmap或WriteableBitmap转换为cv :: Mat?
So my final question: How to convert the SoftwareBitmap or the WriteableBitmap to a cv::Mat?
推荐答案
The problem is that PixelBuffer
is not a void *
, it is an IBuffer^
.
要获取原始数据,可以使用 DataReader
和IBuffer
(如果您希望保留在WinRT中,尽管此技术会数据副本).
To get at the raw data, you can either use the IBufferByteAccess
interface if you're comfortable with COM programming, or you can initialize a DataReader
with an IBuffer
if you'd prefer to stay in WinRT (although this technique will make a copy of the data).
这篇关于在c ++/cx中将SoftwareBitmap或WriteableBitmap转换为cv :: Mat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!