Video Data: Color Data)

Source: Internet
Author: User

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:
 
 
  1. // Kinect object
  2. KinectSensor kinectsensor = null;
  3. Private void Window_Closing (object sender, System. ComponentModel. CancelEventArgs e)
  4. {
  5. If (kinectsensor. Status = KinectStatus. Connected)
  6. {
  7. Kinectsensor. Stop (); // Stop Kinect
  8. }
  9. }
  10.  
  11. Private void Window_Loaded (object sender, RoutedEventArgs e)
  12. {
  13. Foreach (KinectSensor ks in KinectSensor. KinectSensors)
  14. {
  15. If (ks. Status = KinectStatus. Connected)
  16. {
  17. Kinectsensor = ks;
  18. // Enable the color stream. The parameter is the collection method, with a resolution of X and a collection frequency of 30 frames per second.
  19. Kinectsensor. ColorStream. Enable (ColorImageFormat. RgbResolution640x480Fps30 );
  20. // Subscribe to collection events
  21. Kinectsensor. ColorFrameReady + = kinectsensor_ColorFrameReady;
  22. Kinectsensor. Start (); // Start Kinect
  23. This. Title = "Kinect started working ...... ";
  24. Return;
  25. }
  26. }
  27. }
  28.  
  29. Byte [] colorPixels; // byte array for data collection
  30. WriteableBitmap colorBitmap; // bitmap object
  31. Void kinectsensor_ColorFrameReady (object sender, ColorImageFrameReadyEventArgs e)
  32. {
  33. Using (ColorImageFrame colorFrame = e. OpenColorImageFrame ())
  34. {
  35. If (colorFrame! = Null) // determine whether the color data framework has data
  36. {
  37. // Initialize the length of the byte data
  38. This. colorPixels = new byte [kinectsensor. ColorStream. FramePixelDataLength];
  39. // Copy data to the byte array
  40. ColorFrame. CopyPixelDataTo (colorPixels );
  41. // Instantiate a color bitmap
  42. ColorBitmap = new WriteableBitmap (kinectsensor. ColorStream. FrameWidth, kinectsensor. ColorStream. FrameHeight, 96.0, 96.0, PixelFormats. Bgr32, null );
  43. // Load byte data in place
  44. This. colorBitmap. WritePixels (new Int32Rect (0, 0, colorBitmap. PixelWidth, colorBitmap. PixelHeight), colorPixels, colorBitmap. PixelWidth * sizeof (int), 0 );
  45. // Assign the bitmap to the image control and display it
  46. Img. Source = colorBitmap;
  47. }
  48. }
  49. }

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.