internal void DrawColorFrame(Image <Bgra, byte> pColorImage) { m_Image.Width = pColorImage.Width; m_Image.Height = pColorImage.Height; UtilitiesImage.ToImage(m_Image, pColorImage); }
/// <summary> /// Event handler for Kinect sensor's ColorFrameReady event /// </summary> /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> void Instance_allFramesReady(object pSource, Image <Bgra, byte> pColorImage, Image <Bgra, byte> pColorImageCropped, Image <Gray, Int32> pDepthImage, Image <Gray, Int32> pDepthImageCropped) { Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { if (gui_inizialized) { m_Image.Height = pColorImage.Height; m_Image.Width = pColorImage.Width; gui_inizialized = true; } pColorImage.Draw(new Rectangle(m_RectAssemblyArea.X, m_RectAssemblyArea.Y, m_RectAssemblyArea.Width, m_RectAssemblyArea.Height), new Bgra(0, 255, 0, 0), 0); pColorImage.Draw(new Rectangle(m_RectDrawingArea.X, m_RectDrawingArea.Y, m_RectDrawingArea.Width, m_RectDrawingArea.Height), new Bgra(255, 0, 0, 0), 0); UtilitiesImage.ToImage(m_Image, pColorImage); }) ); }
public void ProcessFrame(Image <Bgra, byte> pColorImage, Image <Bgra, byte> pColorImageCropped, Image <Gray, Int32> pDepthImage, Image <Gray, Int32> pDepthImageCropped) { if (pColorImage != null) { m_ColorImage = pColorImage; UtilitiesImage.ToImage(this.KinectRGBImage, CameraManager.Instance.ColorImage); } if (pColorImageCropped != null) { UtilitiesImage.ToImage(this.KinectRGBCropImage, CameraManager.Instance.ColorImageCropped); } if (pDepthImage != null) { UtilitiesImage.ToImage(this.KinectDepthImage, CameraManager.Instance.DepthImage); } if (pDepthImageCropped != null) { UtilitiesImage.ToImage(this.KinectDepthCropImage, CameraManager.Instance.DepthImageCropped); } }
//Code to be called within a certain part of the main ProccessFrame Method public void Object_ProccessFrame_Draw(bool hasToUpdateUI, Image <Bgra, Byte> pImage) { if (m_TakeScreenShotFromZone) { if (m_SelectedZone != null) { long now = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; if (now - m_ScreenshotTakenTimestamp > 200) // take picture after 200ms - frame should be gone by then { // crop image Rectangle boundingBox = new Rectangle(m_SelectedZone.X, m_SelectedZone.Y, m_SelectedZone.Width, m_SelectedZone.Height); pImage.ROI = boundingBox; ObjectDetectionManager.Instance.SaveAndAddObjectToDatabase(pImage); SceneManager.Instance.DisableObjectScenes = false; m_TakeScreenShotFromZone = false; m_SelectedZone = null; CvInvoke.cvResetImageROI(pImage); } } } // first clear all the feedback from previous frame SceneManager.Instance.TemporaryObjectsTextScene.Clear(); // should we check for objects? if (SettingsManager.Instance.Settings.ObjectsRecognizeObject && ObjectDetectionManager.Instance.CurrentLayout != null && hasToUpdateUI) { // walk over all zones foreach (ObjectDetectionZone zone in ObjectDetectionManager.Instance.CurrentLayout.ObjectDetectionZones) { // crop image Rectangle boundingBox = new Rectangle(zone.X, zone.Y, zone.Width, zone.Height); pImage.ROI = boundingBox; Image <Gray, byte> grayscaleImage = pImage.Copy().Convert <Gray, byte>(); CvInvoke.cvResetImageROI(pImage); // walk over all objects foreach (TrackableObject obj in Database.DatabaseManager.Instance.Objects) { if (ObjectDetectionManager.Instance.RecognizeObject(obj.EmguImage, grayscaleImage)) { // YAY we found an object // trigger stuff WorkflowManager.Instance.OnObjectRecognized(obj); // update last seen timestamp obj.LastSeenTimeStamp = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; obj.LastSeenZoneId = zone.Id; // display visual feedback Scene.SceneText textItem = ObjectDetectionManager.Instance.createSceneTextHeadingObjectDetectionZone(zone, obj.Name); SceneManager.Instance.TemporaryObjectsTextScene.Add(textItem); } } } } CvInvoke.cvResetImageROI(pImage); if (ObjectDetectionManager.Instance.CurrentLayout != null) { if (SettingsManager.Instance.Settings.ObjectsVisualFeedbackDisplay && (ObjectDetectionManager.Instance.CurrentLayout.ObjectDetectionZones.Count != 0)) { //write boxes MCvFont font = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5); foreach (ObjectDetectionZone z in ObjectDetectionManager.Instance.CurrentLayout.ObjectDetectionZones) { // draw ID pImage.Draw(z.Id + "", ref font, new System.Drawing.Point(z.X, z.Y), new Bgra(0, 0, 0, 0)); // draw Frame if (z.wasRecentlyTriggered()) { pImage.Draw(new Rectangle(z.X, z.Y, z.Width, z.Height), new Bgra(0, 255, 255, 0), 0); } else { pImage.Draw(new Rectangle(z.X, z.Y, z.Width, z.Height), new Bgra(255, 255, 255, 0), 0); } } } UtilitiesImage.ToImage(image, pImage); if (SettingsManager.Instance.Settings.ObjectsVisualFeedbackProject) { SceneManager.Instance.TemporaryObjectsScene.Clear(); // add a temporary scene for each box foreach (ObjectDetectionZone z in ObjectDetectionManager.Instance.CurrentLayout.ObjectDetectionZones) { // false = call from the display loop SceneManager.Instance.TemporaryObjectsScene.Add(ObjectDetectionManager.Instance.createSceneBoxForObjectDetectionZone(z, false)); } } else { SceneManager.Instance.TemporaryObjectsScene.Clear(); } } }
/// <summary> /// Event handler for Kinect sensor's ColorFrameReady event /// </summary> /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> void Instance_allOrgFramesReady(object pSource, Image <Bgra, byte> pColorImage, Image <Gray, Int32> pDepthImage) { Dispatcher.Invoke(DispatcherPriority.DataBind, new Action(() => { Image <Bgra, byte> tempDepth = pDepthImage.Convert <Bgra, byte>(); tempDepth = tempDepth.Resize(sliderDepthRatio.Value, INTER.CV_INTER_LINEAR); Image <Bgra, byte> tempColor = pColorImage.Copy(); int xS = (int)sliderDepthX.Value; int yS = (int)sliderDepthY.Value; int xD = 0; int yD = 0; int xC = 0; int yC = 0; int w = tempDepth.Width; int h = tempDepth.Height; if (xS >= 0 && tempColor.Width < tempDepth.Width + xS) { // rechts raus & links drin w -= tempDepth.Width + xS - tempColor.Width; xC = xS; } else if (xS < 0 && tempColor.Width < tempDepth.Width + xS) { // rechts raus & links raus w = tempColor.Width; xD = -xS; } else if (xS < 0) { // links raus xD = -xS; w += xS; } else { //mitte horizontal xC = xS; } if (yS >= 0 && tempColor.Height < tempDepth.Height + yS) { //unten raus & oben drin h -= tempDepth.Height + yS - tempColor.Height; yC = yS; } else if (yS < 0 && tempColor.Height < tempDepth.Height + yS) { //unten raus & oben raus h = tempColor.Height; yD = -yS; } else if (yS < 0) { //oben raus h += yS; yD = -yS; } else { //mitte vetical yC = yS; } try { //Ausschnitt Setzen tempDepth.ROI = new Rectangle(xD, yD, w, h); tempColor.ROI = new Rectangle(xC, yC, w, h); //Bild Kopieren tempDepth.CopyTo(tempColor); BoundsOkay = true; } catch (CvException) { //Prevent crash when offsets are out of bounds BoundsOkay = false; } //Auschnitt zurück setzen tempColor.ROI = new Rectangle(0, 0, pColorImage.Width, pColorImage.Height); UtilitiesImage.ToImage(m_Image, tempColor); }) ); }