void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (running == true) { running = false; captureThread.Join(); if (camera != IntPtr.Zero) { CLNUIDevice.StopCamera(camera); CLNUIDevice.DestroyCamera(camera); } camera = CLNUIDevice.CreateCamera(devSerial); } if (comboFEED.SelectedIndex == 0) { colorImage = new NUIImage(640, 480); feed.Source = colorImage.BitmapSource; running = true; captureThread = new Thread(delegate() { CLNUIDevice.StartCamera(camera); while (running) { CLNUIDevice.GetCameraColorFrameRGB32(camera, colorImage.ImageData, 500); Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action) delegate() { colorImage.Invalidate(); }); } CLNUIDevice.StopCamera(camera); }); captureThread.IsBackground = true; captureThread.Start(); } else { colorImage = new NUIImage(640, 480); feed.Source = colorImage.BitmapSource; running = true; captureThread = new Thread(delegate() { CLNUIDevice.StartCamera(camera); while (running) { CLNUIDevice.GetCameraDepthFrameRGB32(camera, colorImage.ImageData, 500); Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action) delegate() { colorImage.Invalidate(); }); } CLNUIDevice.StopCamera(camera); }); captureThread.IsBackground = true; captureThread.Start(); } }
public MainWindow() { InitializeComponent(); Closing += new System.ComponentModel.CancelEventHandler(OnClosing); if (CLNUIDevice.GetDeviceCount() < 1) { MessageBox.Show("Is the Kinect plugged in?"); Environment.Exit(0); } string serialString = CLNUIDevice.GetDeviceSerial(0); camera = CLNUIDevice.CreateCamera(serialString); colorImage = new NUIImage(640, 480); depthImage = new NUIImage(640, 480); rawImage = new NUIImage(640, 480); color.Source = colorImage.BitmapSource; depth.Source = depthImage.BitmapSource; running = true; captureThread = new Thread(delegate() { if (CLNUIDevice.StartCamera(camera)) { while (running) { CLNUIDevice.GetCameraColorFrameRGB32(camera, colorImage.ImageData, 0); CLNUIDevice.GetCameraDepthFrameRGB32(camera, depthImage.ImageData, 0); CLNUIDevice.GetCameraDepthFrameRAW(camera, rawImage.ImageData, 0); Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action) delegate() { colorImage.Invalidate(); depthImage.Invalidate(); }); } } }); captureThread.IsBackground = true; captureThread.Start(); }
public MainWindow() { InitializeComponent(); Closing += new System.ComponentModel.CancelEventHandler(OnClosing); if (CLNUIDevice.GetDeviceCount() < 1) { MessageBox.Show("Is the Kinect plugged in?"); Environment.Exit(0); } string serialString = CLNUIDevice.GetDeviceSerial(0); camera = CLNUIDevice.CreateCamera(serialString); colorImage = new NUIImage(640, 480); depthImage = new NUIImage(640, 480); rawImage = new NUIImage(640, 480); color.Source = colorImage.BitmapSource; depth.Source = depthImage.BitmapSource; running = true; captureThread = new Thread(delegate() { if (CLNUIDevice.StartCamera(camera)) { while (running) { CLNUIDevice.GetCameraColorFrameRGB32(camera, colorImage.ImageData, 0); CLNUIDevice.GetCameraDepthFrameRGB32(camera, depthImage.ImageData, 0); CLNUIDevice.GetCameraDepthFrameRAW(camera, rawImage.ImageData, 0); Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)delegate() { colorImage.Invalidate(); depthImage.Invalidate(); }); } } }); captureThread.IsBackground = true; captureThread.Start(); }
public CameraWindow(string devSerial) { InitializeComponent(); Closing += new System.ComponentModel.CancelEventHandler(OnClosing); xp.Minimum = -981; xp.Maximum = 981; yp.Minimum = -981; yp.Maximum = 981; zp.Minimum = -981; zp.Maximum = 981; try { motor = CLNUIDevice.CreateMotor(devSerial); camera = CLNUIDevice.CreateCamera(devSerial); } catch (System.Exception ex) { MessageBox.Show(ex.Message); Environment.Exit(0); } CLNUIDevice.SetMotorPosition(motor, 0); serial.Content = string.Format("Serial Number: {0}", devSerial); accelerometerTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(100), DispatcherPriority.Normal, (EventHandler) delegate(object sender, EventArgs e) { short _x = 0, _y = 0, _z = 0; CLNUIDevice.GetMotorAccelerometer(motor, ref _x, ref _y, ref _z); x.Content = _x.ToString(); xp.Value = _x; y.Content = _y.ToString(); yp.Value = _y; z.Content = _z.ToString(); zp.Value = _z; }, Dispatcher); accelerometerTimer.Start(); led.SelectionChanged += new SelectionChangedEventHandler(led_SelectionChanged); led.SelectedIndex = 0; colorImage = new NUIImage(640, 480); color.Source = colorImage.BitmapSource; depthImage = new NUIImage(640, 480); depth.Source = depthImage.BitmapSource; running = true; captureThread = new Thread(delegate() { // Trace.WriteLine(string.Format("Camera {0:X}", camera.ToInt32())); if (CLNUIDevice.StartCamera(camera)) { while (running) { CLNUIDevice.GetCameraColorFrameRGB32(camera, colorImage.ImageData, 500); CLNUIDevice.GetCameraDepthFrameRGB32(camera, depthImage.ImageData, 0); Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action) delegate() { colorImage.Invalidate(); depthImage.Invalidate(); }); } CLNUIDevice.StopCamera(camera); } }); captureThread.IsBackground = true; captureThread.Start(); }
public CameraWindow(string devSerial) { InitializeComponent(); Closing += new System.ComponentModel.CancelEventHandler(OnClosing); xp.Minimum = -981; xp.Maximum = 981; yp.Minimum = -981; yp.Maximum = 981; zp.Minimum = -981; zp.Maximum = 981; try { motor = CLNUIDevice.CreateMotor(devSerial); camera = CLNUIDevice.CreateCamera(devSerial); } catch (System.Exception ex) { MessageBox.Show(ex.Message); Environment.Exit(0); } CLNUIDevice.SetMotorPosition(motor, 0); serial.Content = string.Format("Serial Number: {0}", devSerial); accelerometerTimer = new DispatcherTimer(TimeSpan.FromMilliseconds(100), DispatcherPriority.Normal, (EventHandler)delegate(object sender, EventArgs e) { short _x = 0, _y = 0, _z = 0; CLNUIDevice.GetMotorAccelerometer(motor, ref _x, ref _y, ref _z); x.Content = _x.ToString(); xp.Value = _x; y.Content = _y.ToString(); yp.Value = _y; z.Content = _z.ToString(); zp.Value = _z; }, Dispatcher); accelerometerTimer.Start(); led.SelectionChanged += new SelectionChangedEventHandler(led_SelectionChanged); led.SelectedIndex = 0; colorImage = new NUIImage(640, 480); color.Source = colorImage.BitmapSource; depthImage = new NUIImage(640, 480); depth.Source = depthImage.BitmapSource; running = true; captureThread = new Thread(delegate() { // Trace.WriteLine(string.Format("Camera {0:X}", camera.ToInt32())); if (CLNUIDevice.StartCamera(camera)) { while (running) { CLNUIDevice.GetCameraColorFrameRGB32(camera, colorImage.ImageData, 500); CLNUIDevice.GetCameraDepthFrameRGB32(camera, depthImage.ImageData, 0); Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)delegate() { colorImage.Invalidate(); depthImage.Invalidate(); }); } CLNUIDevice.StopCamera(camera); } }); captureThread.IsBackground = true; captureThread.Start(); }
public MainWindow() { InitializeComponent(); Closing += new System.ComponentModel.CancelEventHandler(MainWindow_Closing); DataContext = this; TheCharacter = "█"; FromLeft = 0; FromTop = 0; TheFontSize = 9; //xp.Minimum = 0; // set the progress bar min and max //xp.Maximum = 640; //yp.Minimum = 0; //yp.Maximum = 480; try { motor = CLNUIDevice.CreateMotor(); camera = CLNUIDevice.CreateCamera(); CLNUIDevice.SetMotorLED(motor, 3); } catch (System.Exception ex) { System.Windows.MessageBox.Show(ex.ToString()); this.Close(); // no point opening the program if it cant find kinect } ClickWait = new DispatcherTimer(TimeSpan.FromMilliseconds(200), DispatcherPriority.Normal, (EventHandler)delegate(object sender, EventArgs e) { canclick = true; ClickWait.Stop(); }, Dispatcher); //create the images colorImage = new NUIImage(640, 480); color.Source = colorImage.BitmapSource; depthImage = new NUIImage(640, 480); realImage = new NUIImage(640, 480); real.Source = realImage.BitmapSource; //depth.Source = depthImage.BitmapSource; processedImage = new WriteableBitmap(depthImage.BitmapSource); depth.Source = processedImage; // Create camera capture thread running = true; captureThread = new Thread(delegate() { CLNUIDevice.StartCamera(camera); int numLoops = 0; int pixelStep = 3; int loopStep = 1; while (running) { CLNUIDevice.GetCameraDepthFrameRGB32(camera, colorImage.ImageData, 500); //normal feed (top) CLNUIDevice.GetCameraDepthFrameRGB32(camera, depthImage.ImageData, 0); //to be altered feed (bottom) CLNUIDevice.GetCameraColorFrameRGB32(camera, realImage.ImageData, 0); int red = 255; int green = 255; int blue = 255; Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)delegate() { if (numLoops == 0 || numLoops == loopStep) { int height = (int)depthImage.BitmapSource.Height; int width = (int)depthImage.BitmapSource.Width; int stride = (depthImage.BitmapSource.PixelWidth * depthImage.BitmapSource.Format.BitsPerPixel + 7) / 8; byte[] newPixels = new byte[height * width * processedImage.Format.BitsPerPixel / 8]; bool found = false; // Loop through the all the pixels row by row bool foundclick = false; bool draw = false; for (int row = 0; row < height; row = row + pixelStep) {//for each row of pixels for (int col = 0; col < width; col = col + pixelStep) {//for each collumn of pixels // Disregard top 10% and lower 10% to speed up the app if ( row < height* 0.1 || row > height * 0.9) { break; } // Get current pixel //======================================== //Overview of below code: //----------------------- //basically it goes through each pixel.. if it is a certian colour (set via depth) it then changes is colour to white/red/green - i did warn you, its ugly //================================-======= byte[] currentPixel = new byte[4]; depthImage.BitmapSource.CopyPixels(new Int32Rect((int)col, (int)row, 1, 1), currentPixel, stride, 0); /* // Blue Green Red Alpha //Console.WriteLine("Test: " + currentPixel[0] + "," + currentPixel[1] + "," + currentPixel[2] + "," + currentPixel[3]); */ int index = (row * stride) + (col * 4); //IF STATEMENT BELOW: // currentPixel[0] = Blue // currentPixel[1] = Green // currentPixel[2] = Red // currentPixel[3] = Alpha - we dont actually need to use this if (currentPixel[0] == 255 && (currentPixel[1] <= 45 && currentPixel[1] >= 15) && (currentPixel[2] <= 45 && currentPixel[2] >= 15)) // set this to your bacground colour - This is the colour the paper in my demo shows up as { red = 255; green = 255; blue = 255; // if it is found it changes the pixels to white with the above code } //else if (currentPixel[0] == 255 else if ((currentPixel[1] == 255) && (currentPixel[0] == 0 ) && (currentPixel[2] >= 40 && currentPixel[2] <= 150)) //&& (currentPixel[1] <= 50 && currentPixel[1] >= 46) //&& (currentPixel[2] <= 50 && currentPixel[2] >= 46)) // set this to your finger tip touching the background colour { if (col <= 80 && row <= 60) //this if statement checks if the pixel is found in the top right of the screen it will be used as the clicker (thats how i set it up) { red = 0; green = 255; //sets it to come up green blue = 0; if (usemouse == true) // if i have clicked enable mouse { if (canclick == true) // this is the 200 ms gap between clicks i made, if it wasnt there it would click each frame my finger is detected { SendDoubleClick(); // sends single click command (although its named doubble) canclick = false; // disables can click ClickWait.Start(); //starts 200ms wait timer } } } else // if its not in the 'click corner' then it will be used to set the point { red = 255; //sets the fingertip to red green = 0; blue = 0; if (!found) { RawDat(col, row); //Update RawDat and to see the code executed when it finds the finger found = true; } } } else if (currentPixel[0] == 255 // just to make it a bit more tidy, it makes the rest of the hand white instead of black && currentPixel[1] >= 47 && currentPixel[2] >= 47) { red = 255; green = 255; blue = 255; } else // anything else is set to black { /* red = currentPixel[2]; green = currentPixel[1]; blue = currentPixel[0]; */ red = 0; green = 0; blue = 0; } // Set pixel with NEW colour newPixels[index] = (byte)blue; newPixels[index + 1] = (byte)green; newPixels[index + 2] = (byte)red; newPixels[index + 3] = 255; // Draw more pixels // Left pixel if (col >= 4) { newPixels[index - 4] = (byte)blue; newPixels[index - 4 + 1] = (byte)green; newPixels[index - 4 + 2] = (byte)red; newPixels[index - 4 + 3] = 255; } // Top pixel and left to pixel if (row > 0) { newPixels[index - (stride)] = (byte)blue; newPixels[index - (stride) + 1] = (byte)green; newPixels[index - (stride) + 2] = (byte)red; newPixels[index - (stride) + 3] = 255; newPixels[index - (stride) - 4] = (byte)blue; newPixels[index - (stride) - 4 + 1] = (byte)green; newPixels[index - (stride) - 4 + 2] = (byte)red; newPixels[index - (stride) - 4 + 3] = 255; } } } // Draw the entire image stride = (width * processedImage.Format.BitsPerPixel + 7) / 8; processedImage.WritePixels(new Int32Rect(0, 0, width, height), newPixels, stride, 0); numLoops = 0; } colorImage.Invalidate(); realImage.Invalidate(); //depthImage.Invalidate(); numLoops++; }); } CLNUIDevice.StopCamera(camera); }); captureThread.IsBackground = true; captureThread.Start(); }
void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (running == true) { running = false; captureThread.Join(); if (camera != IntPtr.Zero) { CLNUIDevice.StopCamera(camera); CLNUIDevice.DestroyCamera(camera); } camera = CLNUIDevice.CreateCamera(devSerial); } if (comboFEED.SelectedIndex == 0) { colorImage = new NUIImage(640, 480); feed.Source = colorImage.BitmapSource; running = true; captureThread = new Thread(delegate() { CLNUIDevice.StartCamera(camera); while (running) { CLNUIDevice.GetCameraColorFrameRGB32(camera, colorImage.ImageData, 500); Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)delegate() { colorImage.Invalidate(); }); } CLNUIDevice.StopCamera(camera); }); captureThread.IsBackground = true; captureThread.Start(); } else { colorImage = new NUIImage(640, 480); feed.Source = colorImage.BitmapSource; running = true; captureThread = new Thread(delegate() { CLNUIDevice.StartCamera(camera); while (running) { CLNUIDevice.GetCameraDepthFrameRGB32(camera, colorImage.ImageData, 500); Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)delegate() { colorImage.Invalidate(); }); } CLNUIDevice.StopCamera(camera); }); captureThread.IsBackground = true; captureThread.Start(); } }