C # hands-on practice: Development of Kinect V2 (2): Working Principle of the data source and red foreign Demo,
Kinect Architecture
Kinect data mode
1. Sensor
KinectSensor class
private KinectSensor kinectSensor = null;this.kinectSensor = KinectSensor.GetDefault();this.kinectSensor.Open();this.kinectSensor.Close();
2. Source
Various sensors on the source and Kinect
It discloses the metadata of each sensor source and then gives you an entry
Each data type of the somatosensory device displays a source
Attribute (field ):
AudioSource
BodyFrameSource: Get the source of the body framework
BodyIndexFrameSource: Get the source of the body index Frame
ColorFrameSource: Obtain the color frame source.
DepthFrameSource
InfraredFrameSource
LongExposureInfraredFrameSource obtains the source of the infrared frame with long exposure.
3. Reader
With Reader, you can use events to access frames.
Multiple readers can be used on one source.
Reader can be paused
// Create a reader for the infrared frame source and assign it to the instance of the InfraredFrameReader class: reader
InfraredFrameReader reader = sensor. InfraredFrameSource. OpenReader ();
// Register the method for the FrameArrived event. The event is triggered once the frame is captured (ready ).
Reader. FrameArrived + = InfraredReaderFrameArrived;
Enable the reader and subscribe to ready frame events. When a frame comes in, it calls back.
4. Frame References
Frame reference
Frame reference. In the data variable of the frame event, the fact is sent as frame reference.
In this way, you can access the frame itself.
Method:
AcquireFrame
If the frame expires before the event is triggered or before you process it, you can only get an empty frame from the acquired frame method. This is why you need to check the cause.
Attribute:
RelativeTime (relative time) allows you to establish temporary correlation for different frames.
It's not absolute time, it's time that allows you to compare various sources
Usage: 1. register the frame event to obtain the frame reference.
2. Use the using data block. The using data block will automatically process the frame, and the waist is ready to process the next frame.
There is only one type of frame available at a time point. If you do not close or process frames, you cannot get new frames.
void irReader_FrameArrived(InfraredFrameReader sender, InfraredFrameArrivedEventArgs args){ using (InfraredFrame frame = args.FrameReference.AcquireFrame()) { if (frame != null) { // Get what you need from the frame } }}
5. Frame
Frame itself
With frames, you can access and use the actual data.
We recommend that you copy a local copy or directly access the Base Buffer so that you can quickly respond without having to keep the frame in the current available state for a long time.
Each frame has a format such as width and height.
6. FrameDescription class
Inherited from IFrameDescription
Frame description to obtain frame-related data (width and height)
The length of the frame description is measured in pixels.
Output images in Windows App Store using the Red Source
Public sealed partial class MainPage: Page {public MainPage () {this. initializeComponent (); this. loaded + = MainPage_Loaded;} KinectSensor sensor; InfraredFrameReader irReader; ushort [] irData; // stores the data read by the reader. The IR data format is Ushort byte [] irDataConverted; // convert the infrared data into an image and create the WriteableBitmap irBitmap buffer; // provides a bitmap stream that can be written and updated, the converted image is actually the same as the image written in the constructors in The XAML. When the MainPage is built, the event is triggered and the following method is executed: private void MainPage_Loaded (obj Ect sender, RoutedEventArgs e) {// initialization # region sensor = KinectSensor. getDefault (); // obtain the default Kinect irReader = sensor. infraredFrameSource. openReader (); // enable the infrared reader FrameDescription fd = sensor. infraredFrameSource. frameDescription; // create an infrared frame description irData = new ushort [fd. lengthInPixels]; // The length of the frame description is measured in pixels. The 16-digit integer array is 65535 irDataConverted = new byte [fd. lengthInPixels * 4]; // four times for converting IR to RGBA image # FF irBitmap = new WriteableBitmap (fd. width, fd. height); // create a bitmap image. source = irBitmap; # endregion sensor. open (); // 1. open the sensor irReader. frameArrived + = IrReader_FrameArrived; // 2. subscribe to events for the reader} private void IrReader_FrameArrived (InfraredFrameReader sender, javasargs) {// can I obtain the frame using (InfraredFrame irFrame = args from the frame reference in the event array variable. frameReference. acquireFrame () {if (irFrame! = Null) {irFrame. copyFrameDataToArray (irData); // copy the frame data to the array for (int I = 0; I <irData. length; I ++) // cyclically obtain RGBA {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; // A is transparent, the value 255 is not transparent} irDataConverted. copyTo (irBitmap. pixelBuffer); // copy the rgba to the irBitmap In the bitmap buffer. invalidate (); // request to draw or redraw a bitmap }}}}