3

I am working on Kinect emotion recognition using the Affdex SDK, but the "CameraDetector" couldn't support my Kinect sensor. I tried using a webcam and it turned out that the SDK can work with webcams well. Many times I've assigned the "pixels" in the Frame class to Kinect ColorImageFrame but the errors came out.


        KinectSensor _kinect;
        Affdex.FrameDetector _detector = new Affdex.FrameDetector(30,30,1,FaceDetectorMode.LARGE_FACES);
        private void startKinect()
        {
            if (KinectSensor.KinectSensors.Count > 0)
            {
                _kinect = KinectSensor.KinectSensors[0];
                MessageBox.Show("Kinect current statues is: " + _kinect.Status);

            _kinect.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);

            _kinect.ColorFrameReady += new EventHandler<ColorImageFrameReadyEventArgs>(_kinect_ColorFrameReady);

            _kinect.Start();
        }
        else
        {
            MessageBox.Show("No kinect device!");
        }
    }
    private void startAffdex()
    {
        _detector.setClassifierPath("E:\\Program files\\Affectiva\\Affdex SDK\\data");
        _detector.setImageListener(this);
        _detector.setProcessStatusListener(this);
        _detector.setDetectAllEmotions(true);
        _detector.setDetectAllExpressions(true);
        _detector.setDetectAllEmojis(true);
        _detector.setDetectAllAppearances(true);

        _detector.start();
    }

    void _kinect_ColorFrameReady(object sender,ColorImageFrameReadyEventArgs e)
    {
        using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
        {
            if (colorFrame == null)
            {
                return;
            }

            byte[] pixels = new byte[colorFrame.PixelDataLength];
            colorFrame.CopyPixelDataTo(pixels);
            Affdex.Frame _frame = new Affdex.Frame(colorFrame.Width,colorFrame.Height,pixels,Affdex.Frame.COLOR_FORMAT.BGR);
            _detector.process(_frame);

            int stride = colorFrame.Width*4;
            ///Show the color stream
            colorStream.Source =
                BitmapSource.Create(colorFrame.Width, colorFrame.Height,
                96, 96, PixelFormats.Bgr32, null, pixels, stride);
        }
    }
    private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        startKinect();
        startAffdex();
    }
    private void stopKinect()
    {
        if (_kinect != null)
        {
            if(_kinect.Status ==  KinectStatus.Connected)
            {
                _kinect.Stop();
            }
        }
    }
    private void Window_Closed(object sender, EventArgs e)
    {
        stopKinect();
        _detector.stop();
    }

D.Young
  • 31
  • 3

0 Answers0