public List<TableObject> SeperateObjects(ref DepthImage image, out bool[,] boolmap_object, out int[,,] neighbourmap) { //Create 2 seperate depth-images, remove the objects (for hand recognition) and the hand (for object recognition) DepthImage HandImage = image.Clone(); DepthImage ObjectImage = image.Clone(); SplitUpDepthImages(ref HandImage, ref ObjectImage); //For object recognition, create a BooleanXY-Map (true for all objects with a height > 0) bool[,] boolmap_hand = CreateBoolMap(HandImage); boolmap_object = CreateBoolMap(ObjectImage); if (SettingsManager.RecognitionSet.SaveDebugMaps) { Bitmap dm_obj = MapVisualizer.VisualizeDepthImage(ObjectImage, false, false); dm_obj.Save("ObjectDepthImage.bmp"); Bitmap dm_h = MapVisualizer.VisualizeDepthImage(HandImage, false, false); dm_h.Save("HandDepthImage.bmp"); Bitmap bobj = MapVisualizer.VisualizeBoolMap(boolmap_hand, image.Width, image.Height); bobj.Save("boolmap_hand.bmp"); Bitmap bmpo = MapVisualizer.VisualizeBoolMap(boolmap_object, image.Width, image.Height); bmpo.Save("boolmap_object.bmp"); Bitmap ci = MapVisualizer.VisualizeDepthImage(image, false, false); ci.Save("normalized_depthimage.bmp"); } //Run the Hand Recognition HandRecognizer hrec = new HandRecognizer(); HandObject hand = hrec.RecognizeHands(ref boolmap_hand, image.Width, image.Height); //RunTheObjectRecognition ObjectRecognizer orec = new ObjectRecognizer(); List<TableObject> tableObjects = orec.RecognizeObjects(boolmap_object, image, out neighbourmap); //If there is a hand, add it to the TableObjects if (hand != null) tableObjects.Add(hand); //Return the ObjectList return tableObjects; }
private void DoRecognitionWork(object data) { object[] dataArray = (object[]) data; PlanarImage pimg = (PlanarImage) dataArray[0]; int[] deptharray = (int[]) dataArray[1]; Bitmap colorFrame = (Bitmap) dataArray[2]; RecognitionDataPacket rpacket = new DataStructures.RecognitionDataPacket(); DateTime dtBegin = DateTime.Now; //Create DepthImage DepthImage dimg = new DepthImage(deptharray,pimg.Width,pimg.Height); rpacket.rawDepthImage = dimg.Clone(); //Correct the image DepthMapPreprocessor dmp = new DepthMapPreprocessor(); dimg = dmp.ApplyDepthCorrection(dimg, SettingsManager.PreprocessingSet.DefaultCorrectionMap); dimg = dmp.NormalizeHeights(dimg); ObjectSeperator objectSeperator = new ObjectSeperator(); //Seperate objects bool[,] boolmap_object; int[,,] neighbourmap; List<TableObject> objects = objectSeperator.SeperateObjects(ref dimg,out boolmap_object,out neighbourmap); //if supplied, extract the relevant bitmap parts from the ColorFrame if (colorFrame != null) { ObjectVideoBitmapAssigner ovba = new ObjectVideoBitmapAssigner(); ovba.AssignVideoBitmap(objects, colorFrame); } //Extract hand object from table objects if (objects.Where( o => o.GetType() == typeof(HandObject)).Count() > 0) { rpacket.HandObj = (HandObject)objects.Where(o => o.GetType() == typeof (HandObject)).ToArray()[0]; } //Fill DataPacket with Data rpacket.correctedDepthImage = dimg; rpacket.TableObjects = objects; rpacket.objectmap = boolmap_object; rpacket.neighbourmap = neighbourmap; rpacket.bmpVideoFrame = colorFrame; TimeSpan ts = DateTime.Now - dtBegin; rpacket.RecognitionDuration = (int)Math.Round(ts.TotalMilliseconds); if (SettingsManager.RecognitionSet.SaveDebugMaps) { Bitmap bmp = MapVisualizer.VisualizeDepthImage(rpacket.rawDepthImage); bmp.Save("rawDepthImage.bmp"); } //Event OnRecognitionFinished(rpacket); }