void mainWindow_EngineUpdate(object sender, EventArgs e) { Dispatcher.BeginInvoke((Action)delegate { if (mainWindow.IsStopRequested) { return; } videoImage.Source = VideoSources.SharedVideoSources.GetSource(videoSourceType); if (videoSourceType != VideoSourceType.RectifiedTabletopProduct) { //draw fingers unsafe { int fingerNum; ReadLockedWrapperPtr ptr = ResultsDllWrapper.lockFingers(&fingerNum); Finger* fingers = (Finger*)ptr.IntPtr; if (videoSourceType == VideoSourceType.RGB) //transform points { FloatPoint3D[] kinectPoints = new FloatPoint3D[fingerNum]; FloatPoint3D[] rgbPoints = new FloatPoint3D[fingerNum]; for (int i = 0; i < fingerNum; i++) { kinectPoints[i] = new FloatPoint3D() { x = fingers[i].PositionInKinectPersp.x, y = fingers[i].PositionInKinectPersp.y, z = 0 }; } fixed (FloatPoint3D* kinectPointsPtr = kinectPoints, rgbPointsPtr = rgbPoints) { CommandDllWrapper.transformPoints(kinectPointsPtr, rgbPointsPtr, fingerNum, CalibratedCoordinateSystem.Depth2D, CalibratedCoordinateSystem.RGB2D); } for (int i = 0; i < fingerNum; i++) { Canvas.SetLeft(fingerPoints[i], rgbPoints[i].x - FINGER_RADIUS); Canvas.SetTop(fingerPoints[i], rgbPoints[i].y - FINGER_RADIUS); } } else { for (int i = 0; i < fingerNum; i++) { Canvas.SetLeft(fingerPoints[i], fingers[i].PositionInKinectPersp.x); Canvas.SetTop(fingerPoints[i], fingers[i].PositionInKinectPersp.y); } } for (int i = 0; i < fingerNum; i++) { fingerPoints[i].Opacity = 1.0; if (fingers[i].ID == 0) { fingerPoints[i].Fill = Brushes.Orange; } else { fingerPoints[i].Fill = new SolidColorBrush(IntColorConverter.ToColor(fingers[i].ID)); } if (fingers[i].FingerState == FingerState.FingerOnSurface) { fingerPoints[i].Stroke = Brushes.White; } else { fingerPoints[i].Stroke = Brushes.Transparent; } } for (int i = fingerNum; i < fingerPoints.Count; i++) { fingerPoints[i].Opacity = 0; } ResultsDllWrapper.releaseReadLockedWrapperPtr(ptr); } //draw hands unsafe { int handNum; ReadLockedWrapperPtr ptr = ResultsDllWrapper.lockHands(&handNum); Hand* hands = (Hand*)ptr.IntPtr; for (int i = 0; i < handNum; i++) { Canvas.SetLeft(handPoints[i], hands[i].PositionInKinectProj.x - HAND_RADIUS); Canvas.SetTop(handPoints[i], hands[i].PositionInKinectProj.y - HAND_RADIUS); //handPoints[i].Opacity = hands[i].HandType == HandType.TrackingHand ? 1.0 : 0.5; handPoints[i].Opacity = hands[i].Captured > 0 ? 1.0 : 0.0; handPoints[i].Fill = hands[i].HandType == HandType.NewHandHint ? Brushes.Black : new SolidColorBrush(IntColorConverter.ToColor((int)hands[i].ID)); } for (int i = handNum; i < handPoints.Count; i++) { handPoints[i].Opacity = 0; } ResultsDllWrapper.releaseReadLockedWrapperPtr(ptr); } } }); }
public FloatPoint3D[] ShowChessboard() { FloatPoint3D[] refCorners = new FloatPoint3D[(CHESSBOARD_ROWS - 1) * (CHESSBOARD_COLS - 1)]; double width = chessboardCanvas.Width / CHESSBOARD_COLS; double height = chessboardCanvas.Height / CHESSBOARD_ROWS; for (int i = 0; i < CHESSBOARD_ROWS; i++) { for (int j = 0; j < CHESSBOARD_COLS; j++) { if (i >= 1 && j >= 1) { Point innerCornerInCanvas = new Point(width * j, height * i); Point innerCorner = chessboardCanvas.TranslatePoint(innerCornerInCanvas, globalCanvas); refCorners[(i - 1) * (CHESSBOARD_COLS - 1) + (j - 1)] = new FloatPoint3D() { x = (float)innerCorner.X, y = (float)innerCorner.Y, z = 0 }; } if ((i + j) % 2 != 0) { Rectangle rect = new Rectangle() { Width = width, Height = height, Fill = Brushes.White }; Canvas.SetTop(rect, height * i); Canvas.SetLeft(rect, width * j); chessboardCanvas.Children.Add(rect); } } } chessboardBorderCanvas.Visibility = Visibility.Visible; return refCorners; }
public unsafe void DrawCheckpoints(FloatPoint3D* checkPoints, int checkPointNum) { Dispatcher.BeginInvoke((Action)delegate() { checkPointEllipses = new List<Ellipse>(checkPointNum); for (int i = 0; i < checkPointNum; i++) { Ellipse e = new Ellipse() { Width = 10, Height = 10, Stroke = Brushes.Red, StrokeThickness = 2 }; checkPointEllipses.Add(e); globalCanvas.Children.Add(e); Canvas.SetLeft(e, checkPoints[i].x); Canvas.SetTop(e, checkPoints[i].y); } }, null); }
public static extern unsafe FloatPoint3D transformPoint(FloatPoint3D srcPoint, CalibratedCoordinateSystem srcSpace, CalibratedCoordinateSystem dstSpace);
void refreshWorker_DoWork(object sender, DoWorkEventArgs e) { Dispatcher.BeginInvoke((Action)delegate { //draw fingers unsafe { int fingerNum; ReadLockedWrapperPtr ptr = ResultsDllWrapper.lockFingers(&fingerNum); Finger* fingers = (Finger*)ptr.IntPtr; FloatPoint3D[] kinectPoints = new FloatPoint3D[fingerNum]; FloatPoint3D[] rgbPoints = new FloatPoint3D[fingerNum]; for (int i = 0; i < fingerNum; i++) { kinectPoints[i] = new FloatPoint3D() { x = fingers[i].PositionInKinectPersp.x, y = fingers[i].PositionInKinectPersp.y, z = 0 }; } fixed (FloatPoint3D* kinectPointsPtr = kinectPoints, rgbPointsPtr = rgbPoints) { CommandDllWrapper.transformPoints(kinectPointsPtr, rgbPointsPtr, fingerNum, CalibratedCoordinateSystem.Depth2D, CalibratedCoordinateSystem.Table2D); } for (int i = 0; i < fingerNum; i++) { Canvas.SetLeft(fingerPoints[i], rgbPoints[i].x - FINGER_RADIUS); Canvas.SetTop(fingerPoints[i], rgbPoints[i].y - FINGER_RADIUS); fingerPoints[i].Opacity = 1.0; fingerPoints[i].Fill = fingers[i].FingerType == FingerType.OmniFinger ? Brushes.Orange : Brushes.Purple; } for (int i = fingerNum; i < fingerPoints.Count; i++) { fingerPoints[i].Opacity = 0; } ResultsDllWrapper.releaseReadLockedWrapperPtr(ptr); } //draw hands unsafe { int handNum; ReadLockedWrapperPtr ptr = ResultsDllWrapper.lockHands(&handNum); Hand* hands = (Hand*)ptr.IntPtr; FloatPoint3D[] kinectPoints = new FloatPoint3D[handNum]; FloatPoint3D[] projPoints = new FloatPoint3D[handNum]; for (int i = 0; i < handNum; i++) { kinectPoints[i] = new FloatPoint3D() { x = hands[i].PositionInKinectProj.x, y = hands[i].PositionInKinectProj.y, z = 0 }; } fixed (FloatPoint3D* kinectPointsPtr = kinectPoints, projPointsPtr = projPoints) { CommandDllWrapper.transformPoints(kinectPointsPtr, projPointsPtr, handNum, CalibratedCoordinateSystem.Depth2D, CalibratedCoordinateSystem.Table2D); } for (int i = 0; i < handNum; i++) { Canvas.SetLeft(handPoints[i], projPoints[i].x - HAND_RADIUS); Canvas.SetTop(handPoints[i], projPoints[i].y - HAND_RADIUS); handPoints[i].Opacity = hands[i].HandType == HandType.TrackingHand ? 1.0 : 0.5; handPoints[i].Fill = hands[i].HandType == HandType.NewHandHint ? Brushes.White : new SolidColorBrush(IntColorConverter.ToColor((int)hands[i].ID)); } for (int i = handNum; i < handPoints.Count; i++) { handPoints[i].Opacity = 0; } ResultsDllWrapper.releaseReadLockedWrapperPtr(ptr); } }, null); }
public static extern unsafe void systemCalibrationCalibrateDepthCamera(FloatPoint3D* depthCorners, FloatPoint3D* refCorners, int cornerCount);
public static extern unsafe void transformPoints(FloatPoint3D* srcPoints, FloatPoint3D* dstPoints, int pointNum, CalibratedCoordinateSystem srcSpace, CalibratedCoordinateSystem dstSpace);
public static extern unsafe void systemCalibrationDetectChessboardCorner(IntPtr onFinishedCallback, FloatPoint3D* refCorners, int rows, int cols);
public Finger(int id, FloatPoint3D positionInRealWorld, IntPoint3D positionInKinectPersp, FingerType fingerType, FingerState fingerState) { this.id = id; this.positionInKinectProj = positionInKinectPersp; this.positionInRealWorld = positionInRealWorld; this.fingerType = fingerType; this.fingerState = fingerState; }
private void calibrateDepthButton_Click(object sender, RoutedEventArgs e) { FloatPoint3D[] depthCorners = new FloatPoint3D[depthRefEllipses.Count]; for (int i = 0; i < depthRefEllipses.Count; i++) { depthCorners[i].x = (float)(Canvas.GetLeft(depthRefEllipses[i]) + CALIBRATION_POINT_RADIUS); depthCorners[i].y = (float)(Canvas.GetTop(depthRefEllipses[i]) + CALIBRATION_POINT_RADIUS); depthCorners[i].z = 0; } unsafe { fixed (FloatPoint3D* refCornersPtr = refCorners, depthCornersPtr = depthCorners) { CommandDllWrapper.systemCalibrationCalibrateDepthCamera(depthCornersPtr, refCornersPtr, refCorners.Length); isAllCalibrated = true; } } foreach (var ellipse in depthRefEllipses) { depthVideo.UiCanvas.Children.Remove(ellipse); } calibrateDepthButton.IsEnabled = false; calibrateDepthSaveButton.IsEnabled = false; calibrateDepthLoadButton.IsEnabled = false; }
private void video_MouseMove(object sender, MouseEventArgs e) { if (sender == depthVideo) { if (draggingDepthRefPoint != null) { Point mousePoint = e.GetPosition(depthVideo.UiCanvas); Canvas.SetLeft(draggingDepthRefPoint, mousePoint.X - draggingDepthRefPointOffset.X); Canvas.SetTop(draggingDepthRefPoint, mousePoint.Y - draggingDepthRefPointOffset.Y); } } ZoomableVideoUserControl video = sender as ZoomableVideoUserControl; if (isAllCalibrated) { Point mousePos = e.GetPosition(video.UiCanvas); FloatPoint3D p = new FloatPoint3D() { x = (float)mousePos.X, y = (float)mousePos.Y, z = 0 }; CalibratedCoordinateSystem srcSpace; if (sender == depthVideo) { srcSpace = CalibratedCoordinateSystem.Depth2D; } else if (sender == rgbVideo) { srcSpace = CalibratedCoordinateSystem.RGB2D; } else { throw new NotImplementedException(); } unsafe { testPointInTableSurface = CommandDllWrapper.transformPoint(p, srcSpace, CalibratedCoordinateSystem.Table2D); } refreshTestPoint(); } }
/*void refreshWorker_DoWork(object sender, DoWorkEventArgs e) { Dispatcher.BeginInvoke((Action)delegate { if (rgbSource != null) { ReadLockedWrapperPtr ptr = ResultsDllWrapper.lockCalibrationRGBImage(); rgbSource.Lock(); rgbSource.WritePixels(new Int32Rect(0, 0, rgbWidth, rgbHeight), ptr.IntPtr, rgbWidth * rgbHeight * 3, rgbWidth * 3); rgbSource.Unlock(); ResultsDllWrapper.releaseReadLockedWrapperPtr(ptr); rgbVideo.ImageSource = rgbSource; } if (depthSource != null) { ReadLockedWrapperPtr ptr = ResultsDllWrapper.lockCalibrationDepthImage(); depthSource.Lock(); depthSource.WritePixels(new Int32Rect(0, 0, depthWidth, depthHeight), ptr.IntPtr, depthWidth * depthHeight, depthWidth); depthSource.Unlock(); ResultsDllWrapper.releaseReadLockedWrapperPtr(ptr); depthVideo.ImageSource = depthSource; } }, null); }*/ unsafe void onRGBChessboardDetected(FloatPoint3D* checkPoints, int checkPointNum, FloatPoint3D* depthRefPoints, int depthRefPointNum) { projectorFeedbackWindow.DrawCheckpoints(checkPoints, checkPointNum); //draw depth ref corners Dispatcher.BeginInvoke((Action)delegate() { depthRefEllipses = new List<Ellipse>(); for (int i = 0; i < depthRefPointNum; i++) { Ellipse e = new Ellipse() { Fill = Brushes.Yellow, Opacity = 0.8, Stroke = Brushes.Orange, StrokeThickness = CALIBRATION_POINT_STROKE, Width = CALIBRATION_POINT_RADIUS * 2, Height = CALIBRATION_POINT_RADIUS * 2 }; e.MouseDown += new MouseButtonEventHandler(depthRefPoint_MouseDown); depthVideo.UiCanvas.Children.Add(e); Canvas.SetLeft(e, depthRefPoints[i].x - CALIBRATION_POINT_RADIUS); Canvas.SetTop(e, depthRefPoints[i].y - CALIBRATION_POINT_RADIUS); depthRefEllipses.Add(e); } calibrateDepthButton.IsEnabled = true; calibrateDepthSaveButton.IsEnabled = true; calibrateDepthLoadButton.IsEnabled = true; }, null); }