void sensor_AllFramesReady(object sender, Microsoft.Kinect.AllFramesReadyEventArgs e) { if(this.command == "Stop") { Bot.stop(); } if(this.command == "Forward") { Bot.traverse(); } if (this.command == "Right") { Bot.turnRight(); } if (this.command == "Left") { Bot.turnRight(); } xf++; if (xf % 5 == 0) { xf = 0; if (this.command != null) { using (ColorImageFrame colorFrame = e.OpenColorImageFrame()) { using (DepthImageFrame depthFrame = e.OpenDepthImageFrame()) { using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { humanPosition = frameToHuman(skeletonFrame); if (colorFrame != null) { // Copy the pixel data from the image to a temporary array colorFrame.CopyPixelDataTo(this.colorPixels); // Write the pixel data into our bitmap this.colorBitmap.WritePixels( new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight), this.colorPixels, this.colorBitmap.PixelWidth * sizeof(int), 0); // Error here due to OpenCV_core290.dll //int[] objPos = new int[2]; //objPos = tmp.matchColor(ImageProc.colorFrameToImage(colorFrame)); //if (objPos != null) //{ // short blobDepth = getDepthAtPoint(objPos, depthFrame); // this.lblObject.Content = objPos[0] + ", " + objPos[1] + ", " + blobDepth; //} //else //{ // this.lblObject.Content = "Null"; //} System.Drawing.Bitmap bmp = ImageProc.colorFrameToAforge(colorFrame); HSLFiltering filter = new HSLFiltering(); // set color ranges to keep if (objec[0] == -1) { if (command == "Fetching Bottle") { filter.Hue = bottleH; filter.Saturation = bottleS; filter.Luminance = bottleL; } else if (command == "Fetching Box") { filter.Hue = boxH; filter.Saturation = boxS; filter.Luminance = boxL; } //// apply the filter filter.ApplyInPlace(bmp); BlobCounter blobCounter = new BlobCounter(bmp); int i = blobCounter.ObjectsCount; ExtractBiggestBlob fil = new ExtractBiggestBlob(); int[] pp = new int[2]; pp[0] = 0; pp[1] = 0; int h = 0; if (i > 0) { fil.Apply(bmp); pp[0] = fil.BlobPosition.X; pp[1] = fil.BlobPosition.Y; h = fil.Apply(bmp).Height; } short blobDepth = getDepthAtPoint(pp, depthFrame); this.lblObject.Content = pp[0] + ", " + pp[1] + ", " + blobDepth; this.objec[0] = pp[0]; this.objec[1] = pp[1]; this.objec[2] = blobDepth; } else { filter.Hue = botH; filter.Saturation = botS; filter.Luminance = botL; filter.ApplyInPlace(bmp); BlobCounter blobCounter = new BlobCounter(bmp); int i = blobCounter.ObjectsCount; ExtractBiggestBlob fil = new ExtractBiggestBlob(); int[] pp = new int[2]; pp[0] = 0; pp[1] = 0; int h = 0; if (i > 0) { fil.Apply(bmp); pp[0] = fil.BlobPosition.X; pp[1] = fil.BlobPosition.Y; h = fil.Apply(bmp).Height; } short blobDepth = getDepthAtPoint(pp, depthFrame); this.lblBot.Content = pp[0] + ", " + pp[1] + ", " + blobDepth; this.bot[0] = pp[0]; this.bot[1] = pp[1]; this.bot[2] = blobDepth; } //Assign Manual Position to bot and object } if (humanPosition != null) { this.lblHuman.Content = humanPosition[0] + ", " + humanPosition[1] + ", " + humanPosition[2]; } else { this.lblHuman.Content = "No Human detected"; } if (this.path == 0) { if (humanPosition != null) { if (Bot.moveDoraemon(this.bot[0], this.humanPosition[0], this.bot[2], this.humanPosition[2]) == 0) { this.path = 1; } } } else { if (Bot.moveDoraemon(this.bot[0], this.objec[0], this.bot[2], this.objec[2]) == 0) { Bot.stop(); } } } } } this.lbl.Content = command; } } }
void runtime_SkeletonFrameReady(object sender, Microsoft.Kinect.SkeletonFrameReadyEventArgs e) { Skeleton[] skels = null; long ts = 0; using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { skels = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skels); ts = skeletonFrame.Timestamp; } } if (skels != null) { Vector4 accel = this.runtime.Runtime.AccelerometerGetCurrentReading(); stream.ProcessSkeleton(skels, accel, ts); } }