如何使用 OpenCV 解码在两个 UWP 应用之间发送的图像字节?
How do I decode an image bytes sent between two UWP apps using OpenCV?
我正在使用UWP应用服务将转换为byte[]的png图像从一个应用程序(Unity/C#(发送到OpenCV应用程序(C++(进行图像处理。我在传递的字节 [] 上运行 cv::imdecode 时遇到问题,因为 Mat.data 成员总是以 NULL 结尾...我认为将字节数组从 C# 发送到C++时可能存在格式问题?
// Get bytes from webcam using Unity's Texture.EncodeToPNG() function
Byte[] imageBytes = null;
imageBytes = Communications.GetColorBytes();
if (imageBytes != null)
{
// Convert bytes to BitMapImage to display on XAML
BitmapImage image = await ImageFromBytes(imageBytes);
WebcamImage.Source = image;
//Send a message to the app service
var inputs = new ValueSet();
inputs.Add("data", imageBytes);
AppServiceResponse response = await this.connection.SendMessageAsync(inputs);
//If the service responded display the message. We're done!
if (response.Status == AppServiceResponseStatus.Success)
{
Byte[] test = response.Message["result"] as Byte[];
image = await ImageFromBytes(test);
WebcamImageProcessed.Source = image;
return;
}
}
这是解码发送字节的C++ OpenCV 代码[]
auto input = args->Request->Message;
Platform::Array<unsigned char>^ inputData = safe_cast<Platform::IBoxArray<unsigned char>^>(input->Lookup("data"))->Value;
int size = inputData->Length;
// Create the response
auto result = ref new ValueSet();
// decode byte[] and display image on another screen
auto buf = inputData->Data;
std::vector<unsigned char> data(buf, buf + size);
cv::Mat img_scene = cv::imdecode(data, cv::IMREAD_UNCHANGED);
if (img_scene.data == NULL) {
result->Insert("error", 0);
}
else {
cv::namedWindow("Gray image", cv::WindowFlags::WINDOW_AUTOSIZE);
cv::imshow("Gray image", img_scene);
cv::waitKey(0);
}
答:如何使用 C++/cli 从 C# 流到 OpenCV Mat?
cv::imdecode必须为其第一个参数接收另一个矩阵
auto buf = inputData->Data;
cv::Mat img_data1(size, 1, type, buf);
cv::Mat img_scene = cv::imdecode(img_data1, cv::IMREAD_UNCHANGED);
相关文章:
- PC中的程序和PHONE中的本机描述应用程序之间的数据连接
- 如何使用 OpenCV 解码在两个 UWP 应用之间发送的图像字节?
- MSVC 2010 编译应用程序和 MSVC 2019 编译应用程序之间的行为差异
- 如何使用 ALSA API 在应用程序中在单声道和立体声之间切换声音输出?
- 使用命名管道在 C# 和C++应用程序之间进行持续通信
- 在没有外部文件的情况下在应用会话之间保存变量
- C# 和C++应用程序之间的通信
- Electron应用程序和Win32本机桌面应用程序之间的进程间通信
- STD :: cin和Scanf()应用于字符串之间的区别
- 我可以在应用程序之间更改 .proto 文件的命名空间吗?
- Visual Studio 中的套接字 c++ 应用程序无法通过两台计算机之间的以太网连接工作
- 在 API 和应用程序线程之间共享数据
- 如何在 2 个应用程序之间实现拖放?
- 在QT应用程序和Windows Explorer之间剪切和粘贴剪贴板交换
- 如何实现MATLAB和单独的C++应用程序之间的通信
- 在应用程序和驱动程序之间共享内存
- C++在32位应用程序之间传输大量数据以进行视频播放的方法
- VC++和Qt应用程序之间使用共享内存进行通信
- 如何在不同的MS Office版本之间进行C 应用程序切换
- C 和现有PHP应用程序之间的通信