c# – 将WriteableBitmap转换为Bitmap以便在EmguCV中使用
发布时间:2020-12-15 07:51:42 所属栏目:百科 来源:网络整理
导读:在我的代码中,我从字节数组(依次从Kinect)接收WriteableBitmaps,我想把它们变成用于EmguCV的位图.目前这是我的代码: // Copy the pixel data from the image to a temporary array colorFrame.CopyPixelDataTo(this.colorPixels); // Write the pixel data
在我的代码中,我从字节数组(依次从Kinect)接收WriteableBitmaps,我想把它们变成用于EmguCV的位图.目前这是我的代码:
// Copy the pixel data from the image to a temporary array colorFrame.CopyPixelDataTo(this.colorPixels); // Write the pixel data into our bitmap this.colorBitmap.WritePixels( new Int32Rect(0,this.colorBitmap.PixelWidth,this.colorBitmap.PixelHeight),this.colorPixels,this.colorBitmap.PixelWidth * colorFrame.BytesPerPixel,0); BitmapEncoder encoder = new BmpBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(colorBitmap)); MemoryStream ms = new MemoryStream(); encoder.Save(ms); Bitmap b=new Bitmap(ms); Image<Gray,Byte> img = new Image<Gray,Byte>(b); img = img.ThresholdBinary(new Gray(200),new Gray(255)); 我从here获得了代码的下半部分.代码编译和所有内容,但是在我尝试运行程序时挂起(它应该对图像执行一些操作然后将其转换回可以呈现的格式作为一个图像.)暂停我的代码,然后在VS 2013中使用IntelliTrace,我在Image< Gray,Byte>处获得以下异常: img = new Image< Gray,Byte>(b); “抛出了System.ArgumentException:不支持URI格式.”使用替代代码,从我直接从字节到位图的位置给出了同样的错误. (Code can be found here.) 任何人都有关于如何解决此错误或其他方法转换为位图的提示?我是C#& amp;的新手EmguCV和我非常感谢. 解决方法
结果证明所有代码都没问题.我对错误的技术细节不太确定,但是当尝试在WriteableBitmap中编写Gray16图像时会收到错误(将被转换为Emgu图像.)支持Bgr565或其他格式,我相信Gray没有完全实现Gray16.如果执行WinForms应用程序,Format16bppGray也会给出相同的错误.
我决定使用Grey Emgu图像,同时将Bitmap写为Bgr555,这是一个更嘈杂,但总比没有好. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 学习Winform文本类控件(Label、Button、TextBox)
- ruby-on-rails – Rails 3:在rails中使用JSON响应REST动作
- react-native – React Native:错误:重复资源 – Android
- Swift - 故事板storyboard的用法
- C语言内联函数
- Oracle性能调优
- ruby-on-rails – 使用RVM Gemsets&Bundler和RubyMine
- FlexGrid合并单元格 - zhengjiazeng的日志 - 网易博客
- 利用TreeList加载XML文件
- 工作总结35 Oracle RAC的tnsnames.ora参数详解