short [] array to EMGU Image,最快的方式?

时间:2011-02-14 01:48:47

标签: image-processing opencv computer-vision emgucv

我有一个Int16[19200]数组 我想把它变成Image[160,120,1]

这样做的最快方法是什么?

我需要以120fps的速度完成,所以它需要非常高效 由于
SW

1 个答案:

答案 0 :(得分:2)

找到它:

            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();