public override void OnImage(PXCMImage image) { #region 攝影機影像顯示 //Debug.WriteLine("收到影像,格式 : " + image.imageInfo.format); PXCMSession session = QuerySession(); Bitmap bitmapimage; image.QueryBitmap(session, out bitmapimage); BitmapSource source = ToWpfBitmap(bitmapimage); if (image.imageInfo.format == PXCMImage.ColorFormat.COLOR_FORMAT_DEPTH) { MainWindow.mainwin.ProcessDepthImage(source); } else if (image.imageInfo.format == PXCMImage.ColorFormat.COLOR_FORMAT_RGB24) { MainWindow.mainwin.ProcessColorImage(source); } image.Dispose(); #endregion PXCMGesture gesture = QueryGesture(); if (gesture != null) { PXCMGesture.GeoNode node; //PXCMGesture.GeoNode[] nodes = new PXCMGesture.GeoNode[11]; gesture.QueryNodeData(0, NeedNode(), out node); //gesture.QueryNodeData(0, NeedNodes(), nodes); ProcessNode(node); //ProcessNodes(nodes); } }
public override void OnImage(PXCMImage image) { session = QuerySession(); image.QueryBitmap(session, out lastProcessedBitmap); using (Graphics drawer = Graphics.FromImage(lastProcessedBitmap)) { if (locationStatus != pxcmStatus.PXCM_STATUS_ITEM_UNAVAILABLE) { drawer.DrawRectangle(new Pen(new SolidBrush(Color.Red), 1), new Rectangle(new Point((int)faceLocationData.rectangle.x, (int)faceLocationData.rectangle.y), new Size((int)faceLocationData.rectangle.w, (int)faceLocationData.rectangle.h))); } } //Show main image recipient.Image = lastProcessedBitmap; }
public override bool OnNewFrame() { if (isCapturing) { try { PXCMImage img = QueryImage(PXCMImage.ImageType.IMAGE_TYPE_COLOR); Bitmap bitmap; sts = img.QueryBitmap(session, out bitmap); Graphics g = cameraPanel.CreateGraphics(); g.DrawImage(bitmap, new Point(0, 0)); cameraImage = new Bitmap(bitmap); } catch (Exception ex) { ;; } } return(true); }
public override void OnImage(PXCMImage image) { session = QuerySession(); image.QueryBitmap(session, out lastProcessedBitmap); using (Graphics drawer = Graphics.FromImage(lastProcessedBitmap)) { if (locationStatus != pxcmStatus.PXCM_STATUS_ITEM_UNAVAILABLE) { drawer.DrawRectangle(new Pen(new SolidBrush(Color.Red), 1), new Rectangle(new Point((int)faceLocationData.rectangle.x, (int)faceLocationData.rectangle.y), new Size((int)faceLocationData.rectangle.w, (int)faceLocationData.rectangle.h))); } } oldFacePosition = FacePosition(); AddFacePositionToSmooth(new Point((int)faceLandmarkData[6].position.x, (int)faceLandmarkData[6].position.y)); facePosition = FacePosition(); int xDiffAnt = xDiff; int yDiffAnt = yDiff; xDiff = (oldFacePosition.X - facePosition.X); yDiff = (oldFacePosition.Y - facePosition.Y); double dist = Math.Sqrt(xDiff * xDiff + yDiff * yDiff); if ((int)dist >= MOUSE_ARRAY.Length) { dist = MOUSE_ARRAY.Length - 1; } currentCursorSmooth = 10; cursorPosition.X += xDiff * (MOUSE_ARRAY[(int)dist]); cursorPosition.Y -= yDiff * (MOUSE_ARRAY[(int)dist]); //Off limit screen correction if (cursorPosition.X > SystemInformation.VirtualScreen.Width) { cursorPosition.X = SystemInformation.VirtualScreen.Width; } else if (cursorPosition.X < 0) { cursorPosition.X = 0; } if (cursorPosition.Y > SystemInformation.VirtualScreen.Height) { cursorPosition.Y = SystemInformation.VirtualScreen.Height; } else if (cursorPosition.Y < 0) { cursorPosition.Y = 0; } AddCursorPositionToSmooth(cursorPosition); if (parent.isRunning) { Cursor.Position = CursorPosition(); } //Drawing stuff DrawCircle(lastProcessedBitmap, facePosition, 2, Color.Red); //Show main image recipient.Image = lastProcessedBitmap; }
public override void OnImage(PXCMImage image) { session = QuerySession(); image.QueryBitmap(session, out lastProcessedBitmap); using (Graphics drawer = Graphics.FromImage(lastProcessedBitmap)) { if (locationStatus != pxcmStatus.PXCM_STATUS_ITEM_UNAVAILABLE) { drawer.DrawRectangle(new Pen(new SolidBrush(Color.Red), 1), new Rectangle(new Point((int)faceLocationData.rectangle.x, (int)faceLocationData.rectangle.y), new Size((int)faceLocationData.rectangle.w, (int)faceLocationData.rectangle.h))); } if (landmarkStatus != pxcmStatus.PXCM_STATUS_ITEM_UNAVAILABLE && faceLandmarkData != null) { drawer.DrawLine(new Pen(new SolidBrush(Color.Red), 1), new Point((int)faceLandmarkData[0].position.x, (int)faceLandmarkData[0].position.y), new Point((int)faceLandmarkData[1].position.x, (int)faceLandmarkData[1].position.y)); drawer.DrawLine(new Pen(new SolidBrush(Color.Red), 1), new Point((int)faceLandmarkData[2].position.x, (int)faceLandmarkData[2].position.y), new Point((int)faceLandmarkData[3].position.x, (int)faceLandmarkData[3].position.y)); drawer.DrawLine(new Pen(new SolidBrush(Color.Red), 1), new Point((int)faceLandmarkData[4].position.x, (int)faceLandmarkData[4].position.y), new Point((int)faceLandmarkData[5].position.x, (int)faceLandmarkData[5].position.y)); drawer.DrawRectangle(new Pen(new SolidBrush(Color.Red), 1), new Rectangle((int)faceLandmarkData[6].position.x - 2, (int)faceLandmarkData[6].position.y - 2, 4, 4)); } } //Show main image recipient.Image = lastProcessedBitmap; }
public override bool OnNewFrame() { float x, y; PXCMGesture gesture = QueryGesture(); PXCMGesture.GeoNode ndata; pxcmStatus sts = gesture.QueryNodeData(0, PXCMGesture.GeoNode.Label.LABEL_BODY_HAND_PRIMARY, out ndata); if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) { Console.WriteLine("node HAND_MIDDLE ({0},{1},{2},{3},{4})", ndata.positionImage.x, ndata.positionImage.y, ndata.confidence, ndata.openness, ndata.opennessState); x = ndata.positionImage.x; if (x > 260) { x = 260; } if (x < 40) { x = 40; } x = x - 40; ////////////////////////////////////////////////// x = 220 - x; if (ndata.opennessState == PXCMGesture.GeoNode.Openness.LABEL_CLOSE) { Game.Update1((float)(x - 110) / 110, 1, 1); } // /* * } * sts = gesture.QueryNodeData(0, PXCMGesture.GeoNode.Label.LABEL_BODY_HAND_PRIMARY, out ndata); * if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR) * { * Console.WriteLine("node HAND_MIDDLE ({0},{1},{2},{3},{4})", ndata.positionImage.x, ndata.positionImage.y, ndata.confidence, ndata.openness, ndata.opennessState); * //*/ int state; if (ndata.opennessState == PXCMGesture.GeoNode.Openness.LABEL_OPEN) { state = 0; } else { state = 1; } // Game.Update((float)Program.game.Width * (160 - ndata.positionImage.x) / 160, (float)Program.game.Height * (ndata.positionImage.y - 100) / 100, state, 0); x = ndata.positionImage.x; y = ndata.positionImage.y; //////////////////////////////////////////////// ///////////////Smoothing of coordinate nad removing data outside less presice rang////////////// if (x > 260) { x = 260; } if (x < 40) { x = 40; } if (y > 200) { y = 200; } if (y < 20) { y = 20; } x = x - 40; y = y - 20; ////////////////////////////////////////////////// x = 220 - x; if (Game.gd.Gamestate != 0) { Game.Update(Program.game.Width * x / 220, Program.game.Height * y / 180, state, 0); } } PXCMImage img = QueryImage(PXCMImage.ImageType.IMAGE_TYPE_COLOR); if (img != null) { img.QueryBitmap(QuerySession(), out bmp); } if (bmp != null) { Main.camerapre = GetTexture(Main.GrDev, bmp); } bmp = null; img = QueryImage(PXCMImage.ImageType.IMAGE_TYPE_DEPTH); if (img != null) { img.QueryBitmap(QuerySession(), out bmp); } if (bmp != null) { Main.camerapre1 = GetTexture(Main.GrDev, bmp); } bmp = null; img = QueryImage(PXCMImage.ImageType.IMAGE_TYPE_MASK); if (img != null) { img.QueryBitmap(QuerySession(), out bmp); } if (bmp != null) { Main.camerapre2 = GetTexture(Main.GrDev, bmp); } return(loop); }