// image received from web cam private void WebCamCapture_ImageCaptured(object source, WebCam_Capture.WebcamEventArgs e) { Bitmap image = new Bitmap(e.WebCamImage); Bitmap currentFrame = image; Bitmap differenceImage = null; Bitmap thresholdImage = null; Bitmap findBodyAndHandColours = null; Bitmap model = null; if(previousFrame != null) { Bitmap grayScaledCurrent = imageProcessing.grayscale(currentFrame); Bitmap grayScaledPrevious = imageProcessing.grayscale(previousFrame); Bitmap averagedCurrent = imageProcessing.averaging(grayScaledCurrent); Bitmap averagedPrevious = imageProcessing.averaging(grayScaledPrevious); differenceImage = imageProcessing.subtraction(averagedCurrent, averagedPrevious); thresholdImage = imageProcessing.iterativeThreshold(differenceImage); findBodyAndHandColours = imageProcessing.findBodyAndHand(currentFrame); gestureRecognition.makeModel(findBodyAndHandColours); model = gestureRecognition.drawModel(240, 320); if(interact) { DateTime currentTime = DateTime.Now; int difference = (currentTime - initialTime).Seconds; if (!interactionReady) { interactionTimeLabel.Text = waitingTime - difference + " seconds till interaction "; if (difference >= waitingTime) { interactionReady = true; gestureRecognition.setInteractionReady(true); gestureRecognition.setPreviousLowestBodyYPosition(); interactionTimeLabel.Text = "Ready"; } } else { proxmityTextField.Text = gestureRecognition.getProximity(); approachingDetractingTextField.Text = gestureRecognition.getApproachingOrDetracting(); handGestureTextField.Text = gestureRecognition.getHandGesture(); gestureRecognition.calculateBodyMotion(thresholdImage); motionLevelTextField.Text = (gestureRecognition.getMotionLevel()) + " %"; currentProximity = gestureRecognition.getProximity(); if(currentProximity != previousProximity) { if(robot.getIsSeeing()) { robot.see(currentProximity); previousProximity = currentProximity; } } } } } if (currentFrameCheckBox.Checked) { currentImage.Image = currentFrame; } else { currentImage.Image = null; } if (motionDetectionCheckBox.Checked) { motionImage.Image = thresholdImage; } else { motionImage.Image = null; } if (colorDetectionCheckBox.Checked) { colordetectionImage.Image = findBodyAndHandColours; } else { colordetectionImage.Image = null; } if (modelCheckBox.Checked) { modelImage.Image = model; } else { modelImage.Image = null; } previousFrame = currentFrame; }
/// <summary> /// Called every time the webcam gets a new image, which depends /// on the refresh rate determined in the settings menu /// </summary> /// <param name="source"></param> /// <param name="e"></param> private void WebCamCapture_ImageCaptured(object source, WebCam_Capture.WebcamEventArgs e) { // set the picturebox picture this.pictureBox1.Image = e.WebCamImage; }
/// <summary> /// An image was capture /// </summary> /// <param name="source">control raising the event</param> /// <param name="e">WebCamEventArgs</param> private void WebCamCapture_ImageCaptured(object source, WebCam_Capture.WebcamEventArgs e) { // set the picturebox picture this.pictureBox1.Image = e.WebCamImage; if (File.Exists("c:\\stream.bmp")) { File.Delete("c:\\stream.bmp"); } // todo: send to server byte[] bytes = ImageConverter.imageToByteArray(e.WebCamImage); Image img = ImageConverter.byteArrayToImage(bytes); img.Save("c:\\stream.bmp"); _clientControl.SendWebcamCapture(bytes); }