On Kinect for windows, there are three cameras, One infrared emission camera, one infrared camera, and one common camera. This blog article shows how a common camera collects video data. In addition, deep Data collection (Depth Data) and bone Data (Skeleton Data) are described in the following blog posts.
For project preparation, see the previous blog. Create a new WPF project and put an Image control on the form. The Name is img. C # The Code is as follows:
- // Kinect object
- KinectSensor kinectsensor = null;
- Private void Window_Closing (object sender, System. ComponentModel. CancelEventArgs e)
- {
- If (kinectsensor. Status = KinectStatus. Connected)
- {
- Kinectsensor. Stop (); // Stop Kinect
- }
- }
-
- Private void Window_Loaded (object sender, RoutedEventArgs e)
- {
- Foreach (KinectSensor ks in KinectSensor. KinectSensors)
- {
- If (ks. Status = KinectStatus. Connected)
- {
- Kinectsensor = ks;
- // Enable the color stream. The parameter is the collection method, with a resolution of X and a collection frequency of 30 frames per second.
- Kinectsensor. ColorStream. Enable (ColorImageFormat. RgbResolution640x480Fps30 );
- // Subscribe to collection events
- Kinectsensor. ColorFrameReady + = kinectsensor_ColorFrameReady;
- Kinectsensor. Start (); // Start Kinect
- This. Title = "Kinect started working ...... ";
- Return;
- }
- }
- }
-
- Byte [] colorPixels; // byte array for data collection
- WriteableBitmap colorBitmap; // bitmap object
- Void kinectsensor_ColorFrameReady (object sender, ColorImageFrameReadyEventArgs e)
- {
- Using (ColorImageFrame colorFrame = e. OpenColorImageFrame ())
- {
- If (colorFrame! = Null) // determine whether the color data framework has data
- {
- // Initialize the length of the byte data
- This. colorPixels = new byte [kinectsensor. ColorStream. FramePixelDataLength];
- // Copy data to the byte array
- ColorFrame. CopyPixelDataTo (colorPixels );
- // Instantiate a color bitmap
- ColorBitmap = new WriteableBitmap (kinectsensor. ColorStream. FrameWidth, kinectsensor. ColorStream. FrameHeight, 96.0, 96.0, PixelFormats. Bgr32, null );
- // Load byte data in place
- This. colorBitmap. WritePixels (new Int32Rect (0, 0, colorBitmap. PixelWidth, colorBitmap. PixelHeight), colorPixels, colorBitmap. PixelWidth * sizeof (int), 0 );
- // Assign the bitmap to the image control and display it
- Img. Source = colorBitmap;
- }
- }
- }
The result is as follows:
650) this. width = 650; "style =" height: 253px; width: 329px "border =" 0 "alt =" "width =" 29 "height =" 31 "src =" http://www.bkjia.com/uploads/allimg/131228/16240B429-0.jpg "/>
This article is from "Gui Su Wei" blog, please be sure to keep this source http://axzxs.blog.51cto.com/730810/1184448