unity3d中图像导出到OpenCV中
2013-10-28 15:59
375 查看
首先从相机或者Texture中获得存储图像块
Color32[] pixels = Texture2D.GetPixels32();
//或者WebCamTexture.GetPixels32 ();
再使用GCHandle获得块的指针
GCHandle pixelHandle = GCHandle.Alloc(pixels, GCHandleType.Pinned);
IntPtr pixelPointer = pixelHandle.AddrOfPinnedObject();
然后将此指针传递给OpenCV使用即可。以dll方式进行数据传递。
unity3d中调用如下
][DllImport(@"Unity2OpenCVImage.dll")]
private static extern void Unity2OpenCVImage(IntPtr data,int width,int height,int stride);
opencv中的dll函数为
Color32[] pixels = Texture2D.GetPixels32();
//或者WebCamTexture.GetPixels32 ();
再使用GCHandle获得块的指针
GCHandle pixelHandle = GCHandle.Alloc(pixels, GCHandleType.Pinned);
IntPtr pixelPointer = pixelHandle.AddrOfPinnedObject();
然后将此指针传递给OpenCV使用即可。以dll方式进行数据传递。
unity3d中调用如下
][DllImport(@"Unity2OpenCVImage.dll")]
private static extern void Unity2OpenCVImage(IntPtr data,int width,int height,int stride);
opencv中的dll函数为
void Unity2OpenCVImage(char* imageData,int width,int height,int stride) { if(NULL==imageData) { return; } cv::Mat opencvImage(height,width,CV_8UC4); memcpy(opencvImage.data,imageData,stride*height); cv::cvtColor(opencvImage,opencvImage,CV_BGR2RGB); // cv::imshow("11",opencvImage); // cv::waitKey(1); } }
相关文章推荐
- opencv2 矩阵方式 resize图像缩放代码(转载)
- 在OpenCV中图像边界扩展 copyMakeBorder 的实现
- 【OpenCV学习笔记】之六 手写图像旋转函数---万丈高楼平地起
- OpenCV学习笔记(三)——Mat,图像的新容器
- 用opencv开源包实现了下图像拼接
- 八.使用OpenCv对图像进行平滑操作
- opencv学习笔记(十五)——图像融合
- Mat - 基本图像容器(OPencv 入门必看)
- opencv-03--图像的算术运算
- VS 中图像插件的使用(OpenCV)
- UNITY3D 导出Android 报错:The versions of the Android Gradle plugin and Gradle are not compatible
- opencv学习之图像凸包
- 【OpenCV3图像处理】线性滤波:均值滤波,高斯滤波
- python深度学习库pytorch::transforms练习:opencv,scikit-image,PIL图像处理库比较
- opencv常用图像处理函数(C版本)
- OPenCV3.2 调整图像对比度与亮度
- 移动设备上使用opencv 1.10做图像识别的例子
- opencv从视频中获取一帧帧图像(五)
- OpenCv入门(二)-图像处理基本函数
- 继承opencv的CImage类在MFC的单文档中编辑并显示图像的方法