short[] array to EMGU Image , fastest way?
I have an array of Int16[19200]
Image[160,120,1]
What is the fastest way of doing this?
I need to do it at 120fps, so it needs to be really efficient.
Thanks SWFound it:
GCHandle handle = GCHandle.Alloc(dataArray, GCHandleType.Pinned);
IntPtr imageHeaderForBytes = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MIplImage)));
CvInvoke.cvInitImageHeader(
imageHeaderForBytes,
new Size(160, 120),
Emgu.CV.CvEnum.IPL_DEPTH.IPL_DEPTH_16S, 1, 0, 4);
Marshal.WriteIntPtr(
imageHeaderForBytes,
(int)Marshal.OffsetOf(typeof(MIplImage), "imageData"),
handle.AddrOfPinnedObject());
CvInvoke.cvCopy(imageHeaderForBytes, EMGUImage.Ptr, IntPtr.Zero);
Marshal.FreeHGlobal(imageHeaderForBytes);
handle.Free();
精彩评论