0

Kinect カメラ 2 (SDK v2) を Emgu ライブラリ (2.4.10.1940) で使用するプロジェクトに取り組んでいます。

最初に KinectColorFrameをに変換しBitmapSource、次に からBitmapSourceに変換しましたDrawing.BitmapDrawing.Bitmapからに変換しようとするとImage<Bgr, Byte>、「mscorlib.dll で 'System.ArgumentException' 型の初回例外が発生しました。追加情報: URI 形式はサポートされていません」というメッセージが表示されます。

誰かがアイデアを持っていますか、または誰かが別の方法でそれを行う方法を教えてくれますか?

以下に、私が使用したコードを示します。

    public MainWindow()
    {
        InitializeComponent();

        kinectSensor = KinectSensor.GetDefault();

        if (kinectSensor == null)
            return;

        FrameDescription colorFrameDescription = kinectSensor.ColorFrameSource.FrameDescription;

        colorReader = kinectSensor.ColorFrameSource.OpenReader();

        colorPixels = new byte[colorFrameDescription.Width * colorFrameDescription.Height * BytePerPixel];

        colorBitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
        kinectSensor.Open();

        colorReader.FrameArrived += colorReader_FrameArrived;

        kinectSensor.IsAvailableChanged += kinectSensor_IsAvailableChanged;
        StatusText = kinectSensor.IsAvailable ? "Running" : "Kinect sensor not available";
    }

        void colorReader_FrameArrived(object sender, ColorFrameArrivedEventArgs e)
        {
            using (ColorFrame colorFrame = e.FrameReference.AcquireFrame())
            {
                if (colorFrame == null)
                    return;

                FrameDescription colorFrameDesc = colorFrame.FrameDescription;
                // Check if the pixelWidth and pixelHeight is right
                if ((colorFrameDesc.Width == colorBitmap.PixelWidth) && (colorFrameDesc.Height == colorBitmap.PixelHeight))
                {
                    // Check if the image format is right.
                    if (colorFrame.RawColorImageFormat == ColorImageFormat.Bgra)
                        colorFrame.CopyRawFrameDataToArray(this.colorPixels);
                    else
                        colorFrame.CopyConvertedFrameDataToArray(this.colorPixels, ColorImageFormat.Bgra);
                    // Write pixels to BitmapSource format
                    colorBitmap.WritePixels(new Int32Rect(0, 0, colorFrameDesc.Width, colorFrameDesc.Height),
                        colorPixels,
                        colorFrameDesc.Width * BytePerPixel,
                        0);
                    // Convert to Drawing.Bitmap image
                    System.Drawing.Bitmap bmap = BitmapImage2Bitmap(colorBitmap);
                    // Convert to Emgu image (This is where I get my error).
                    Emgu.CV.Image<Bgr, byte> imageFrame = new Image<Bgr,byte>(bmap);
                }
            }
        }

        private System.Drawing.Bitmap BitmapImage2Bitmap(BitmapSource bitmapImage)
        {
            using (MemoryStream outStream = new MemoryStream())
            {
                BitmapEncoder enc = new BmpBitmapEncoder();
                enc.Frames.Add(BitmapFrame.Create(bitmapImage));
                enc.Save(outStream);
                System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(outStream);

                return new System.Drawing.Bitmap(bitmap);
            }
        }

4

1 に答える 1

1

こんにちはみんな私は問題を見つけて解決しました。まず、x86 および x64 フォルダーを Emgu\bin から Visual Studio ディレクトリの Debug フォルダーにコピーするのを忘れていました。さらに、に変換Media.BitmapSourceするEmgu.CV.Imageのは最善のアイデアではないので、本 (James Ashley - Beginning Kinect Programming with Microsoft SDK) を読んだ後、 に変換できDrawing.BitmapましたEmgu.CV.Image

       private void InitializeKinect()
        {
            KinectSensor Sensor = KinectSensor.GetDefault();

            FrameDescription frameDescription = Sensor.ColorFrameSource.FrameDescription;

            ColorFrameReader FrameReader = Sensor.ColorFrameSource.OpenReader();

            FrameReader.FrameArrived += FrameReader_FrameArrived;
          }

        void FrameReader_FrameArrived(object sender, ColorFrameArrivedEventArgs e)
        {
            using (ColorFrame frame = e.FrameReference.AcquireFrame())
            {
                if (frame == null)
                    return;
            var width = frame.FrameDescription.Width;
            var heigth = frame.FrameDescription.Height;
            var data = new byte[width * heigth * System.Windows.Media.PixelFormats.Bgra32.BitsPerPixel / 8];
            frame.CopyConvertedFrameDataToArray(data, ColorImageFormat.Bgra);
              
            var bitmap = new System.Drawing.Bitmap(width, height, PixelFormat.Format32bppRgb);
            var bitmapData = bitmap.LockBits(
                new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height),
                ImageLockMode.WriteOnly,
                bitmap.PixelFormat);
            Marshal.Copy(data, 0, bitmapData.Scan0, data.Length);
            bitmap.UnlockBits(bitmapData);
              
              Emgu.CV.Image<Bgr, Byte> imageFrame = new Image<Bgr, Byte>(bitmap);
                
            }
        }

于 2015-06-11T07:39:00.213 に答える