EEC-693/793 Applied Computer Vision with Depth Cameras

Slides:



Advertisements
Similar presentations
5/19/2015 EEC484/584: Computer Networks 1 EEC-490 Senior Design (CE) Kinect Programming Tutorial 1 Wenbing Zhao
Advertisements

EEC-492/592 Kinect Application Development Lecture 15 Wenbing Zhao
Work With Skeleton Data
Page 1 | Microsoft Work With Color Data Kinect for Windows Video Courses Jan 2013.
C# Event Processing Model Solving The Mystery. Agenda Introduction C# Event Processing Macro View Required Components Role of Each Component How To Create.
EEC-492/592 Kinect Application Development
EEC-492/592 Kinect Application Development Lecture 10 Wenbing Zhao
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Events and Timers. Event handlers ScratchC#/VS 2 Script == event handler.
1 EEC-492/592 Kinect Application Development Lecture 2 Wenbing Zhao
12/5/2015 EEC492/693/793 - iPhone Application Development 1 EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 4 Wenbing Zhao
Controls Part 2. DateTimePicker Control Used for representing Date/Time information and take it as input from user. Date information is automatically.
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 8 Wenbing Zhao
2/16/2016 EEC492/693/793 - iPhone Application Development 1 EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 4 Wenbing Zhao
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 17.1 Test-Driving the Student Grades Application.
3/3/2016 EEC492/693/793 - iPhone Application Development 1 EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 4 Wenbing Zhao
1.NETDelegates & eventsNOEA / PQC 2007 Delegates & events Observer pattern Delegates –Semantics –Cil – code –Usage Events Asynchronious delegates.
REC [ ] How to implement CAMERA RECORDING for USB WEBCAM or IP CAMERA in C#.NET SOURCE CODE: ! Welcome to this presentation that explains.
EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 9 Wenbing Zhao
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-492/592 Kinect Application Development
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
C# Event Processing Model
CIS 470 Mobile App Development
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
Simple Windows Applications
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-490 Senior Design (CE)
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-492/592 Kinect Application Development
EEC-492/592 Kinect Application Development
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
Additional Topics in VB.NET
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
Android Sensor Programming
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
Presentation transcript:

EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 5 Wenbing Zhao wenbing@ieee.org 5/4/2019 EEC492/693/793 - iPhone Application Development

Outline Important Classes on Color Image Retrieving/Setting Color Image Format Capturing Frames on Demand Frame Number Frame rate Saving frames Extend the KinectCam app with more controls 2

Important Classes on Color Image We have dealt with two classes related to Kinect color images ColorImageStream: handles a stream of ColorImageFrame ColorImageFrame ColorImageStream this.sensor.ColorStream.Enable(); ColorStream is of ColorImageStream type ColorImageFrame imageFrame = e.OpenColorImageFrame()

ColorImageStream Infrared data: 16 bits per pixel at 640x480 at 30 FPS Sealed class: no other class can inhert a sealed class

ColorImageFrame

More on ColorImageFrame

Retrieving/Setting Color Image Format Can retrieve the color image format for the current image frame using the ImageFrame.Format property public ColorImageFormat ImageFormat {get;set;} Retrieve format this.ImageFormat = imageFrame.Format; Setting format this.sensor.ColorStream.Enable(RgbResolution640x480Fps30);

Capturing Frames on Demand Polling: request an image frame on demand ColorImageStream::openNextFrame() OpenNextFrame() accepts one parameter specifying how long the sensor should wait before it sends the image frame If there is no frame ready within the provided time, the method will return null In the polling model, the application opens a channel for the stream, and whenever the application needs a frame, it sends a request to get the frame int millisecondsWait = 10; if (this.sensor.ColorStream.IsEnabled) { ColorImageFrame colorImageFrame = this.sensor.ColorStream. OpenNextFrame(millisecondsWait); }

Frame Number Frame number: Every frame has a number to identify the frame This number is incremented with each new frame generated It is read only in image frame int frameNumber=imageFrame.FrameNumber;

Frame Rate Calculation private int TotalFrames; private DateTime lastTime = DateTime.MaxValue; private int LastFrames; int currentFrameRate = 0; private int GetCurrentFrameRate() { ++this.TotalFrames; DateTime currentTime = DateTime.Now; var timeSpan = currentTime.Subtract(this.lastTime); if (this.lastTime == DateTime.MaxValue || // first time to run timeSpan >= TimeSpan.FromSeconds(1)) // average 1 second { currentFrameRate = (int)Math.Round((this.TotalFrames - this. LastFrames) / timeSpan.TotalSeconds); this.LastFrames = this.TotalFrames; this.lastTime = currentTime; } return currentFrameRate;

Saving Color Image private void SaveImage() { using (FileStream fs = new FileStream(string.Format("{0}.jpg", Guid.NewGuid().ToString()), System.IO.FileMode.Create)) { BitmapSource imageSource = (BitmapSource)image1.Source; JpegBitmapEncoder jpegEncoder = new JpegBitmapEncoder(); jpegEncoder.Frames.Add(BitmapFrame.Create(imageSource)); jpegEncoder.Save(fs); fs.Close(); }

Saving Color Images Periodically Call the SaveImage () method on a Tick event of DispatcherTimer Automatic periodic image saving. 4 steps. Step1: Define the DispatcherTimer object under the System.Windows.Threading namespace: private DispatcherTimer timer = new DispatcherTimer();

Saving Color Images Periodically Step 2: Write the start method with an interval of 10 seconds and attach the Tick event handler: public void StartTimer() { this.timer.Interval = new TimeSpan(0, 0, 10); this.timer.Start(); this.timer.Tick += handleTickEvent; } // handleTickEvent: event handler delegate to be implemented

Saving Color Images Periodically Step 3: On the Tick event handler, call the SaveImage() method: public void handleTickEvent(object sender, object e) { if (this.sensor.IsRunning && this.sensor.ColorStream.IsEnabled) this.SaveImage(); } Step 4: To launch the timer thread, call timer.StartTimer();

Saving Color Images Periodically To stop timer public void StopTimer() { this.timer.Stop(); this.timer.Tick -= this.handleTickEvent; }

Adjusting Elevation Angle Kinect elevation angle can be changed between MaxElevationAngle (27 degrees) MinElevationAngle (-27 degrees) Adjusting angle private void SetSensorAngle(int angleValue) { if(angleValue > sensor.MinElevationAngle || angleValue < sensor.MaxElevationAngle) this.sensor.ElevationAngle = angleValue; }

Build KinectCam2.0 Extend the KinectCam we built last time Revise GUI design Adding image controls Add code to handle image controls

Revised GUI

Settings Changing frame format on the fly RgbResolution640x480Fps30, enable this by default RgbResolution1280x960Fps12 Customize the checkbox names and the event handlers this time private void ChangeToHighResolution(object sender, RoutedEventArgs e) { if (this.sensor != null) { this.normalresolution.IsChecked = false; this.sensor.ColorStream.Enable( ColorImageFormat.RgbResolution1280x960Fps12); this.colorPixels = new byte[this.sensor.ColorStream.FramePixelDataLength]; }

Settings Changing frame format on the fly Enable one, and disable the other Need to reset the colorPixels array length for different formats private void ChangeToNormalResolution (object sender, RoutedEventArgs e) { if (this.sensor != null) { this.highresolution.IsChecked = false; this.sensor.ColorStream.Enable( ColorImageFormat.RgbResolution640x480Fps30); this.colorPixels = new byte[this.sensor.ColorStream.FramePixelDataLength]; }

Settings Displaying frame rate Changing elevation angle Calculated and displayed for each frame received At the end of void colorFrameReady(object sender, ColorImageFrameReadyEventArgs e) textBox1.Text = ""+GetCurrentFrameRate(); Changing elevation angle private void IncrementAngle(object sender, RoutedEventArgs e) { int angleValue = this.sensor.ElevationAngle + 1; if (angleValue < sensor.MaxElevationAngle) { this.sensor.ElevationAngle = angleValue; this.AngleBox.Text = "" + angleValue; } private void DecrementAngle(object sender, RoutedEventArgs e) { int angleValue = this.sensor.ElevationAngle - 1; if (angleValue > sensor.MinElevationAngle) ……

Settings Save image on demand (Save Image button) private void SaveImage(object sender, RoutedEventArgs e) { SaveImage(); } private void SaveImage() using (FileStream fileStream = new FileStream(string.Format("{0}.jpg", Guid.NewGuid().ToString()), System.IO.FileMode.Create)) BitmapSource imageSource = (BitmapSource)image1.Source; JpegBitmapEncoder jpegEncoder = new JpegBitmapEncoder(); jpegEncoder.Frames.Add(BitmapFrame.Create(imageSource)); jpegEncoder.Save(fileStream); fileStream.Close();

Settings Save image periodically (via checkbox) Make sure you designate event handler for both checked and unchecked event!

Settings Save image periodically (via checkbox) private void PeriodicSavingChanged (object sender, RoutedEventArgs e) { if (checkBox1.IsChecked == true) { StartTimer(); } else { this.timer.Stop(); } } private DispatcherTimer timer = new DispatcherTimer(); public void StartTimer() { this.timer.Interval = new TimeSpan(0, 0, 10); this.timer.Start(); this.timer.Tick += this.handleTickEvent; public void StopTimer() { this.timer.Stop(); this.timer.Tick -= this.handleTickEvent; public void handleTickEvent(object sender, object e) { if (this.sensor.IsRunning && this.sensor.ColorStream.IsEnabled) { this.SaveImage();