在c ++/cx中将SoftwareBitmap或WriteableBitmap转换为cv :: Mat [英] Converting a SoftwareBitmap or WriteableBitmap to cv::Mat in c++/cx

查看:194
本文介绍了在c ++/cx中将SoftwareBitmap或WriteableBitmap转换为cv :: Mat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在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^.

要获取原始数据,可以使用

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屋!

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