Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ColorImageFrame不能用于kinect v2(VS2013 C#kinect SDK v2)_C#_Opencv_Kinect_Emgucv - Fatal编程技术网

ColorImageFrame不能用于kinect v2(VS2013 C#kinect SDK v2)

ColorImageFrame不能用于kinect v2(VS2013 C#kinect SDK v2),c#,opencv,kinect,emgucv,C#,Opencv,Kinect,Emgucv,(RGB解决方案640x480FPS30)存在问题 public partial class TrainWPF : Window { KinectSensor kinectSensor = null; ColorImageFormat imageFormat = ColorImageFormat.RgbResolution640x480Fps30; ColorImageFrame最初可以使用kinect v1,但不能在kinect v2中使用如何在k

(RGB解决方案640x480FPS30)存在问题

      public partial class TrainWPF : Window
{

    KinectSensor kinectSensor = null;
    ColorImageFormat imageFormat = ColorImageFormat.RgbResolution640x480Fps30;       
ColorImageFrame最初可以使用kinect v1,但不能在kinect v2中使用如何在kinect v2中使用ColorImageFrame /////停止&ColorFrameReady&Dispose无法使用

            private void DeActivateSensor()
    {
        if (kinectSensor != null)
        {
            kinectSensor.Stop();
            kinectSensor.ColorFrameReady -= new EventHandler<ColorImageFrameReadyEventArgs>(sensor_ColorFrameReady);
            kinectSensor.Dispose();
        }
    }

    private void SetupSensorVideoInput()
    {
        if (kinectSensor != null)
        {
            imageFormat = (ColorImageFormat)cmbDisplayMode.SelectedItem;
            kinectSensor.ColorStream.Enable(imageFormat);

            kinectSensor.ColorFrameReady += new EventHandler<ColorImageFrameReadyEventArgs>(sensor_ColorFrameReady);
            kinectSensor.Start();
        }
    }        
    void sensor_ColorFrameReady(object sender, ColorFrameArrivedEventArgs e)
    {
        using (ColorImageFrame image = e.OpenColorImageFrame())
        {
            if (image == null)
                return;

            Image<Bgr, byte> currentImage = EmguImageExtensions.ToOpenCVImage<Bgr, byte>(image);
            Image<Gray, byte> grayFrame = currentImage.Convert<Gray, byte>();

            System.Drawing.Rectangle[] facesDetected = Face.DetectMultiScale(grayFrame, 1.2, 10, new System.Drawing.Size(50, 50), System.Drawing.Size.Empty);

            for (int i = 0; i < facesDetected.Length; i++)// (Rectangle face_found in facesDetected)
            {
                //This will focus in on the face from the haar results its not perfect but it will remove a majoriy
                //of the background noise

                facesDetected[i].X += (int)(facesDetected[i].Height * 0.15);
                facesDetected[i].Y += (int)(facesDetected[i].Width * 0.22);
                facesDetected[i].Height -= (int)(facesDetected[i].Height * 0.3);
                facesDetected[i].Width -= (int)(facesDetected[i].Width * 0.35);

                result = currentImage.Copy(facesDetected[i]).Convert<Gray, byte>().Resize(100, 100, Emgu.CV.CvEnum.INTER.CV_INTER_CUBIC);
                result._EqualizeHist();
                face_PICBX.Source = result.ToBitmapSource();
            }

            if (colorBytes == null ||
                colorBytes.Length != image.PixelDataLength)
            {
                colorBytes = new byte[image.PixelDataLength];
            }

            image.CopyPixelDataTo(colorBytes);

            BitmapSource source = BitmapSource.Create(image.Width,
                image.Height,
                96,
                96,
                PixelFormats.Bgr32,
                null,
                colorBytes,
                image.Width * image.BytesPerPixel);
            picVideoDisplay.Source = source; 


        }
    }
    private Bitmap ImageToBitmap(ColorImageFrame Image)
    {
        byte[] pixeldata = new byte[Image.PixelDataLength];
        Image.CopyPixelDataTo(pixeldata);
        Bitmap bmap = new Bitmap(Image.Width, Image.Height,     System.Drawing.Imaging.PixelFormat.Format32bppRgb);
        BitmapData bmapdata = bmap.LockBits(
            new System.Drawing.Rectangle(0, 0, Image.Width, Image.Height),
            ImageLockMode.WriteOnly,
            bmap.PixelFormat);
        IntPtr ptr = bmapdata.Scan0;
        Marshal.Copy(pixeldata, 0, ptr, Image.PixelDataLength);
        bmap.UnlockBits(bmapdata);
        return bmap;
    }
private void deactivatesesensor()
{
如果(kinectSensor!=null)
{
kinectSensor.Stop();
kinectSensor.ColorFrameReady-=新事件处理程序(传感器\u ColorFrameReady);
kinectSensor.Dispose();
}
}
私有void SetupSensorVideoInput()
{
如果(kinectSensor!=null)
{
imageFormat=(ColorImageFormat)CMB显示模式。选择编辑项;
kinectSensor.ColorStream.Enable(图像格式);
kinectSensor.ColorFrameReady+=新事件处理程序(传感器\u ColorFrameReady);
kinectSensor.Start();
}
}        
无效传感器\u ColorFrameReady(对象发送器,ColorFrameArrivedEventArgs e)
{
使用(ColorImageFrame image=e.OpenColorImageFrame())
{
if(image==null)
返回;
Image currentImage=EmguImageExtensions.ToOpenCVImage(图像);
Image grayFrame=currentImage.Convert();
System.Drawing.Rectangle[]facesDetected=Face.DetectMultiScale(灰色框架,1.2,10,新系统.Drawing.Size(50,50),系统.Drawing.Size.Empty);
对于(int i=0;i