EmguCv inside Unity

Hey guys, I am using EmguCv wrapper inside Unity to develop some game. Right now, Iam confronted with problem of CONVERTATION *IplImage*(Image) to Texture2D(unity texture). I've read a lot of posts before and implemented one idea: Unfortunately it workes only for histogram drawing. What I've done there: Firstly, I convert Image to Image, then I got ManagedArray of bytes from Image and set the data to newly created Texture2D:

CvInvoke.cvCvtColor(img.Ptr, copy_img, COLOR_CONVERSION.CV_BGR2RGBA); Array bytes = copy_img.ManagedArray; int h = bytes.GetLength(0); int w = bytes.GetLength(1);

for (int i = 0; i

t.SetPixel(y, x, new UnityEngine.Color((float)r, (float)g, (float)b, (float)a));

} }

http://unity3d.qatohost.com/questions/23450/mono-and-missing-types-using-external-library.html

Maybe, you can use this code block for taking image to texture…

using UnityEngine;
using System.Collections;
using Emgu.CV;
using Emgu.CV.Util;
using Emgu.CV.CvEnum;
using Emgu.CV.Structure;
using System.IO;

	private Capture cap;
	Texture2D camera;
	
	void Start()
	{
		cap = new Capture(0);
	}
	
	
	void Update()
	{
		using (Image<Bgr, byte> nextFrame = cap.QueryFrame())
		{
			if (nextFrame != null)
			{ 
				System.Drawing.Bitmap bitmapCurrentFrame = nextFrame.ToBitmap ();
				MemoryStream m = new MemoryStream ();
				bitmapCurrentFrame.Save (m, bitmapCurrentFrame.RawFormat);

				if(camera!=null){
					GameObject.Destroy(camera);
				}
				camera = new Texture2D (400, 400);
				
				camera.LoadImage (m.ToArray ());
				renderer.material.mainTexture = camera;
			}
		}
		
	}