简体   繁体   中英

Kinect C# overload

I have just started learning kinect, and I tried following one of the examples online, but I am returned this error:

No overload for 'msfr_MultiSourceFrameArrived matches delegate 'TypedEventHandler'

I pointed out where the error line is at in the code, which is above the sensor.Open in MainPage

How my code looks like :

            KinectSensor sensor;
    InfraredFrameReader irReader;
    ushort[] irData;
    byte[] irDataConverted;
    WriteableBitmap irBitmap;

    Body[] bodies;
    MultiSourceFrameReader msfr;

    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        sensor = KinectSensor.GetDefault();
        irReader = sensor.InfraredFrameSource.OpenReader();
        FrameDescription fd = sensor.InfraredFrameSource.FrameDescription;
        irData = new ushort[fd.LengthInPixels];
        irDataConverted = new byte[fd.LengthInPixels * 4];
        irBitmap = new WriteableBitmap(fd.Width, fd.Height);
        image.Source = irBitmap;

        bodies = new Body[6];
        msfr = sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Body| FrameSourceTypes.Infrared);
        msfr.MultiSourceFrameArrived += msfr_MultiSourceFrameArrived; <-- the error

        sensor.Open();
    }

    void msfr_MultiSourceFrameArrived(MultiSourceFrameReader sender, MultiSourceFrame args)
    {
        using (MultiSourceFrame msf = args.BodyFrameReference.AcquireFrame())
        {
            if (msf != null)
            {
                using (BodyFrame bodyFrame = msf.BodyFrameReference.AcquireFrame())
                {
                    using (InfraredFrame irFrame = msf.InfraredFrameReference.AcquireFrame())
                    {
                        if (bodyFrame != null && irFrame != null)
                        {
                            irFrame.CopyFrameDataToArray(irData);

                            for (int i = 0; i < irData.Length; i++)
                            {
                                byte intensity = (byte)(irData[i] >> 8);
                                irDataConverted[i * 4] = intensity;
                                irDataConverted[i * 4 + 1] = intensity;
                                irDataConverted[i * 4 + 2] = intensity;
                                irDataConverted[i * 4 + 3] = 255;
                            }
                            irDataConverted.CopyTo(irBitmap.PixelBuffer);
                            irBitmap.Invalidate();

                            bodyFrame.GetAndRefreshBodyData(bodies);
                            bodyCanvas.Children.Clear();
                            foreach (Body body in bodies)
                            {
                                if (body.IsTracked)
                                {
                                    Joint headJoint = body.Joints[JointType.Head];
                                    if (headJoint.TrackingState == TrackingState.Tracked)
                                    {
                                        DepthSpacePoint dsp = sensor.CoordinateMapper.MapCameraPointsToDepthSpace(headJoint.Position);
                                        Ellipse headCircle = new Ellipse() { Width = 50, Height = 50, Fill = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0)) };
                                        bodyCanvas.Children.Add(headCircle);
                                        Canvas.SetLeft(headCircle, dsp.X-25);
                                        Canvas.SetTop(headCircle, dsp.Y-25);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

Try changing the argument in msfr_MultiSourceFrameArrived() from MultiSourceFrame args to MultiSourceFrameArrivedEventArgs args

The MultiSourceFrameArrived event of the FrameReader is expecting a specific type of eventhandler argument and it's telling you the one you currently use is not what it's expecting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM