/// <summary> /// Execute startup tasks /// </summary> /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> private void WindowLoaded(object sender, RoutedEventArgs e) { // Create the drawing group we'll use for drawing this.drawingGroup = new DrawingGroup(); // Create an image source that we can use in our image control this.imageSource = new DrawingImage(this.drawingGroup); // Display the drawing using our image control Image.Source = this.imageSource; // Look through all sensors and start the first connected one. // This requires that a Kinect is connected at the time of app startup. // To make your app robust against plug/unplug, // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit foreach (var potentialSensor in KinectSensor.KinectSensors) { if (potentialSensor.Status == KinectStatus.Connected) { this.sensor = potentialSensor; break; } } if (null != this.sensor) { TransformSmoothParameters parameters = new TransformSmoothParameters(); parameters.Smoothing = 0.2f; parameters.Correction = 0.8f; parameters.Prediction = 0.0f; parameters.JitterRadius = 0.5f; parameters.MaxDeviationRadius = 0.5f; // Turn on the skeleton stream to receive skeleton frames this.sensor.SkeletonStream.Enable(parameters); // Add an event handler to be called whenever there is new color frame data this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady; // Start the sensor! try { this.sensor.Start(); } catch (IOException) { this.sensor = null; } } if (null == this.sensor) { this.statusBarText.Text = Properties.Resources.NoKinectReady; } try { tcp = new System.Net.Sockets.TcpClient(ipAddress, port); tcp.NoDelay = false; tcp.ReceiveTimeout = 7000; //tcp.NoDelay = false; stream = tcp.GetStream(); easyWriter = new System.IO.StreamWriter(stream); easyWriter.AutoFlush = true; // easyWriter.Write("M00\n"); easyReader = new System.IO.StreamReader(stream); } catch (System.ArgumentNullException ee) { System.Console.WriteLine("ArgumentNullException: {0}", ee); } catch (System.Net.Sockets.SocketException ee) { System.Console.WriteLine("SocketException: {0}", ee); } }
public PenExample() { // Create several geometries. RectangleGeometry myRectangleGeometry = new RectangleGeometry(); myRectangleGeometry.Rect = new Rect(0, 0, 50, 50); EllipseGeometry myEllipseGeometry = new EllipseGeometry(); myEllipseGeometry.Center = new Point(75, 75); myEllipseGeometry.RadiusX = 50; myEllipseGeometry.RadiusY = 50; LineGeometry myLineGeometry = new LineGeometry(); myLineGeometry.StartPoint = new Point(75, 75); myLineGeometry.EndPoint = new Point(75, 0); // Create a GeometryGroup and add the geometries to it. GeometryGroup myGeometryGroup = new GeometryGroup(); myGeometryGroup.Children.Add(myRectangleGeometry); myGeometryGroup.Children.Add(myEllipseGeometry); myGeometryGroup.Children.Add(myLineGeometry); // Create a GeometryDrawing and use the GeometryGroup to specify // its geometry. GeometryDrawing myGeometryDrawing = new GeometryDrawing(); myGeometryDrawing.Geometry = myGeometryGroup; // Add the GeometryDrawing to a DrawingGroup. DrawingGroup myDrawingGroup = new DrawingGroup(); myDrawingGroup.Children.Add(myGeometryDrawing); // Create a Pen to add to the GeometryDrawing created above. Pen myPen = new Pen(); myPen.Thickness = 10; myPen.LineJoin = PenLineJoin.Round; myPen.EndLineCap = PenLineCap.Round; // Create a gradient to use as a value for the Pen's Brush property. GradientStop firstStop = new GradientStop(); firstStop.Offset = 0.0; Color c1 = new Color(); c1.A = 255; c1.R = 204; c1.G = 204; c1.B = 255; firstStop.Color = c1; GradientStop secondStop = new GradientStop(); secondStop.Offset = 1.0; secondStop.Color = Colors.Purple; LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(); myLinearGradientBrush.GradientStops.Add(firstStop); myLinearGradientBrush.GradientStops.Add(secondStop); myPen.Brush = myLinearGradientBrush; myGeometryDrawing.Pen = myPen; // Create an Image and set its DrawingImage to the Geometry created above. Image myImage = new Image(); myImage.Stretch = Stretch.None; myImage.Margin = new Thickness(10); DrawingImage myDrawingImage = new DrawingImage(); myDrawingImage.Drawing = myDrawingGroup; myImage.Source = myDrawingImage; this.Content = myImage; }
private GeometryModel3D createSingleImageMesh(Point3D[,] slicedGrid, int dim, Matrix genMatrix, Color borderColor, ImageSource image, BitmapSource blankImage) { try { ImageSource sliceImage = image; Rect sliceImageRect = new Rect(0, 0, sliceImage.Width, sliceImage.Height); DrawingGroup dg = new DrawingGroup(); if (blankImage != null) { dg.Children.Add(new ImageDrawing(blankImage, sliceImageRect)); } dg.Children.Add(new ImageDrawing(sliceImage, sliceImageRect)); RectangleGeometry rGeometry = new RectangleGeometry(sliceImageRect); dg.Children.Add(new GeometryDrawing(null, new Pen(new SolidColorBrush(borderColor), 1), rGeometry)); dg.ClipGeometry = new RectangleGeometry(sliceImageRect); if (dim == 0) { if (CurrentShape != null && CurrentShape.PathPoints != null) { GeometryDrawing gd; if (CurrentShape.PathPoints.Count > 0) { gd = DrawRegion(CurrentShape); } else { gd = null; } if (gd != null) { dg.Children.Add(gd); } } } sliceImage = new DrawingImage(dg); Point3D p0 = slicedGrid[dim, 0]; Point3D p1 = slicedGrid[dim, 1]; Point3D p2 = slicedGrid[dim, 2]; Point3D p3 = slicedGrid[dim, 3]; Point3DCollection positionsFront = new Point3DCollection() { p0, p1, p3, p3, p1, p2 }; MeshGeometry3D meshGeometry3DFront = new MeshGeometry3D(); meshGeometry3DFront.Positions = positionsFront; GeometryModel3D sliceGeometryModelFront = new GeometryModel3D(); sliceGeometryModelFront.Geometry = meshGeometry3DFront; meshGeometry3DFront.TextureCoordinates = texturePointsFront; ImageBrush imageBrushTransformed = new ImageBrush(sliceImage); imageBrushTransformed.RelativeTransform = new MatrixTransform(genMatrix); DiffuseMaterial imageMaterial = new DiffuseMaterial(imageBrushTransformed); imageMaterial.Freeze(); sliceGeometryModelFront.Material = imageMaterial; sliceGeometryModelFront.BackMaterial = imageMaterial; meshGeometry3DFront.Freeze(); sliceGeometryModelFront.Freeze(); return(sliceGeometryModelFront); } catch { return(null); } }
//////////////// //DO NOT TOUCH// //////////////// /// <summary> /// Initializes a new instance of the MainWindow class. /// </summary> public MainWindow() { // one sensor is currently supported this.kinectSensor = KinectSensor.GetDefault(); // get the coordinate mapper this.coordinateMapper = this.kinectSensor.CoordinateMapper; // get the depth (display) extents FrameDescription frameDescription = this.kinectSensor.DepthFrameSource.FrameDescription; // get size of joint space this.displayWidth = frameDescription.Width; this.displayHeight = frameDescription.Height; // open the reader for the body frames this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader(); // a bone defined as a line between two joints this.bones = new List <Tuple <JointType, JointType> >(); // Torso this.bones.Add(new Tuple <JointType, JointType>(JointType.Head, JointType.Neck)); this.bones.Add(new Tuple <JointType, JointType>(JointType.Neck, JointType.SpineShoulder)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.SpineMid)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineMid, JointType.SpineBase)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipLeft)); // Right Arm this.bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderRight, JointType.ElbowRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.ElbowRight, JointType.WristRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.HandRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.HandRight, JointType.HandTipRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.ThumbRight)); // Left Arm this.bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderLeft, JointType.ElbowLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.ElbowLeft, JointType.WristLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.HandLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.HandLeft, JointType.HandTipLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.ThumbLeft)); // Right Leg this.bones.Add(new Tuple <JointType, JointType>(JointType.HipRight, JointType.KneeRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.KneeRight, JointType.AnkleRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.AnkleRight, JointType.FootRight)); // Left Leg this.bones.Add(new Tuple <JointType, JointType>(JointType.HipLeft, JointType.KneeLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.KneeLeft, JointType.AnkleLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.AnkleLeft, JointType.FootLeft)); // populate body colors, one for each BodyIndex this.bodyColors = new List <Pen>(); this.bodyColors.Add(new Pen(Brushes.Red, 6)); this.bodyColors.Add(new Pen(Brushes.Orange, 6)); this.bodyColors.Add(new Pen(Brushes.Green, 6)); this.bodyColors.Add(new Pen(Brushes.Blue, 6)); this.bodyColors.Add(new Pen(Brushes.Indigo, 6)); this.bodyColors.Add(new Pen(Brushes.Violet, 6)); // set IsAvailableChanged event notifier this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged; // open the sensor this.kinectSensor.Open(); // set the status text this.StatusText = this.kinectSensor.IsAvailable ? Properties.Resources.RunningStatusText : Properties.Resources.NoSensorStatusText; // Create the drawing group we'll use for drawing this.drawingGroup = new DrawingGroup(); // Create an image source that we can use in our image control this.imageSource = new DrawingImage(this.drawingGroup); // use the window object as the view model in this simple example this.DataContext = this; // initialize the components (controls) of the window this.InitializeComponent(); //dynamically add a grid uniGrid.Rows = numGridRows; uniGrid.Columns = numGridCols; //rows left->right rectArray = new Rectangle[numGridRows, numGridCols]; imgArray = new Image[numGridRows, numGridCols]; Image temp_img; for (int rr = 0; rr < numGridRows; rr++) { for (int cc = 0; cc < numGridCols; cc++) { rectArray[rr, cc] = new Rectangle() { Stroke = System.Windows.Media.Brushes.Black, // Height = (int)(gridHeight / numGridRows), //Width = (int)(gridWidth / numGridRows), }; temp_img = new Image(); BitmapImage bm = new BitmapImage(); bm.BeginInit(); bm.UriSource = new Uri("", UriKind.Relative); bm.EndInit(); temp_img.Source = bm; imgArray[rr, cc] = temp_img; uniGrid.Children.Add(rectArray[rr, cc]); uniImgGrid.Children.Add(imgArray[rr, cc]); } } //student storage initialization gridArray = new int[numGridRows, numGridCols]; int delay = 30 * 8; zeroGridArray(); WaterGotHit = System.Windows.Media.Brushes.Gray; ShipGotHit = System.Windows.Media.Brushes.Red; ShipDead = System.Windows.Media.Brushes.Black; isPlayerOneHandClosed = false; hasPlayerOneHandOpened = false; playerOneHandLocation = new Point(); delayFrames = -1; isGameOver = false; waitingOnBot = false; playerOneTrackingId = 0; needsAllocationPlayerOne = true; clearBoard(); }
/// <summary> /// Initializes a new instance of the KinectBodyView class /// </summary> /// <param name="kinectSensor">Active instance of the KinectSensor</param> public BodyView(KinectSensor kinectSensor) { if (kinectSensor == null) { throw new ArgumentNullException("kinectSensor"); } // gets the coordinate mapper this.coordinateMapper = kinectSensor.CoordinateMapper; // gets the depth display extents FrameDescription frameDescription = kinectSensor.DepthFrameSource.FrameDescription; //Defines the size of the joint space this.displayWidth = frameDescription.Width; this.displayHeight = frameDescription.Height; // a bone defined as a line between two joints this.bones = new List <Tuple <JointType, JointType> >(); // The torso is the center joint of the human body this.bones.Add(new Tuple <JointType, JointType>(JointType.Head, JointType.Neck)); this.bones.Add(new Tuple <JointType, JointType>(JointType.Neck, JointType.SpineShoulder)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.SpineMid)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineMid, JointType.SpineBase)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipLeft)); // Adding the joints of the Right Arm this.bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderRight, JointType.ElbowRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.ElbowRight, JointType.WristRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.HandRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.HandRight, JointType.HandTipRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.ThumbRight)); // Adding the joints of the Left Arm this.bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderLeft, JointType.ElbowLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.ElbowLeft, JointType.WristLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.HandLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.HandLeft, JointType.HandTipLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.ThumbLeft)); //Adding the joints of the Right Leg this.bones.Add(new Tuple <JointType, JointType>(JointType.HipRight, JointType.KneeRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.KneeRight, JointType.AnkleRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.AnkleRight, JointType.FootRight)); //Adding the joints of the Left Leg this.bones.Add(new Tuple <JointType, JointType>(JointType.HipLeft, JointType.KneeLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.KneeLeft, JointType.AnkleLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.AnkleLeft, JointType.FootLeft)); // Each body index is given a color to identify the bodies. // If one body is allowed to track only a color can be given this.bodyColors = new List <Pen>(); this.bodyColors.Add(new Pen(Brushes.Red, 6)); this.bodyColors.Add(new Pen(Brushes.Orange, 6)); this.bodyColors.Add(new Pen(Brushes.Green, 6)); this.bodyColors.Add(new Pen(Brushes.Blue, 6)); this.bodyColors.Add(new Pen(Brushes.Indigo, 6)); this.bodyColors.Add(new Pen(Brushes.Violet, 6)); // A drawing group is created for drawing the body this.drawingGroup = new DrawingGroup(); // An image source for drawing group is created this.imageSource = new DrawingImage(this.drawingGroup); }
/// <summary> /// The ghost gate to be drawn and added to the Sketch. The ghost gates are tracked in /// Edit Menu in currGhosts. It delegates when to draw and undraw these. The Ghosts have /// the shape that is associated with it so that it can update Orientation. /// /// Also the name Ghost gate is super cool /// </summary> /// <param name="shape"></param> /// <param name="SketchPanel"></param> public GhostGate(Sketch.Shape shape, ref SketchPanelLib.SketchPanel sketchPanel, ref GateDrawing.GateDrawing gateDrawer, GateRotatedHandler gateRotated, KeyValuePair <List <string>, List <string> > IO = new KeyValuePair <List <string>, List <string> >()) { // Initialize everything startPoint = new System.Windows.Point(); endPoint = new System.Windows.Point(); subscribed = false; this.shape = shape; this.sketchPanel = sketchPanel; this.gateDrawer = gateDrawer; this.gateRotated = gateRotated; this.SubCircuitDock = new DockPanel(); this.IO = IO; if (!Domain.LogicDomain.IsGate(shape.Type)) { return; } // It makes no sense to lock the drawing ratio if this is a subcircuit, but we need to set it back to normal after bool shouldLock = this.gateDrawer.LockDrawingRatio; if (shape.Type == Domain.LogicDomain.SUBCIRCUIT) { gateDrawer.LockDrawingRatio = false; } // Make the desired image GeometryDrawing ghostGate = gateDrawer.DrawGate(shape.Type, shape.Bounds, false, true, shape.Orientation); // Make textbox to go with the image Popup popup = new Popup(); TextBlock popupText = new TextBlock(); popupText.Text = gateDrawer.DrawingAdvice; popupText.TextWrapping = System.Windows.TextWrapping.Wrap; popupText.Background = Brushes.Pink; popupText.Foreground = Brushes.Black; popup.Child = popupText; popup.IsOpen = false; popup.AllowsTransparency = true; popup.Visibility = System.Windows.Visibility.Visible; popup.PlacementTarget = sketchPanel.InkCanvas; popup.Placement = PlacementMode.RelativePoint; popup.HorizontalOffset = 20; popup.VerticalOffset = 50; drawingAdvice = popup; gateDrawer.LockDrawingRatio = shouldLock; DrawingImage drawingImage = new DrawingImage(ghostGate); relabelImage = new System.Windows.Controls.Image(); relabelImage.Source = drawingImage; relabelImage.Width = drawingImage.Width; relabelImage.Height = drawingImage.Height; // Actually add the image InkCanvas.SetLeft(relabelImage, shape.Bounds.Left); InkCanvas.SetTop(relabelImage, shape.Bounds.Top); // If it's a subcircuit we need to display the name and where inputs/ouputs should be if (shape.Type == Domain.LogicDomain.SUBCIRCUIT) { addIO(shape.Orientation); } sketchPanel.InkCanvas.Children.Add(relabelImage); sketchPanel.InkCanvas.Children.Add(drawingAdvice); }
private void WindowLoaded(object sender, RoutedEventArgs e) { // Create the drawing group we'll use for drawing this.drawingGroup = new DrawingGroup(); // Create an image source that we can use in our image control this.imageSource = new DrawingImage(this.drawingGroup); // Display the drawing using our image control image.Source = this.imageSource; // Look through all sensors and start the first connected one. // This requires that a Kinect is connected at the time of app startup. // To make your app robust against plug/unplug, // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit foreach (var potentialSensor in KinectSensor.KinectSensors) { if (potentialSensor.Status == KinectStatus.Connected) { this.sensor = potentialSensor; break; } } if (null != this.sensor) { TransformSmoothParameters tsp = new TransformSmoothParameters(); tsp.Smoothing = 0.1f; tsp.Correction = 0.01f; tsp.Prediction = 0.3f; tsp.JitterRadius = 0.2f; tsp.MaxDeviationRadius = 0.2f; this.sensor.SkeletonStream.Enable(tsp); /////////////////// COLOR FRAME ACTİVATİON // Turn on the color stream to receive color frames this.sensor.ColorStream.Enable(ColorImageFormat.InfraredResolution640x480Fps30); // Allocate space to put the pixels we'll receive this.colorPixels = new byte[this.sensor.ColorStream.FramePixelDataLength]; // This is the bitmap we'll display on-screen this.colorBitmap = new WriteableBitmap(this.sensor.ColorStream.FrameWidth, this.sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Gray16, null); // Set the image we display to point to the bitmap where we'll put the image data this.imgColorFrame.Source = this.colorBitmap; // Add an event handler to be called whenever there is new color frame data this.sensor.ColorFrameReady += this.SensorColorFrameReady; this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady; try { this.sensor.Start(); } catch (IOException) { this.sensor = null; } InitSerialPort(); DispatcherTimer dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 25); dispatcherTimer.Start(); this.sensor.ElevationAngle = aci; } if (null == this.sensor) { MessageBox.Show("Kinect Can't Detected"); } }
/// <summary> /// Execute startup tasks - Use this for setup that needs to occur after a Kinect is available /// </summary> /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> private void WindowLoaded(object sender, RoutedEventArgs e) { // Create the drawing group we'll use for drawing this.drawingGroup = new DrawingGroup(); // Create an image source that we can use in our image control this.imageSource = new DrawingImage(this.drawingGroup); // Display the drawing using our image control Canvas.Source = this.imageSource; // Look through all sensors and start the first connected one. // This requires that a Kinect is connected at the time of app startup. // To make your app robust against plug/unplug, // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit (See components in Toolkit Browser). foreach (var potentialSensor in KinectSensor.KinectSensors) { if (potentialSensor.Status == KinectStatus.Connected) { this.sensor = potentialSensor; break; } } // Ensure that we have a sensor before continuing if (null != this.sensor) { // Turn on the proper streams to receive event frames // Disable lines for event streams you are not using this.sensor.SkeletonStream.Enable(); this.sensor.ColorStream.Enable(); this.sensor.DepthStream.Enable(); // Add an event handlers to be called whenever there is new color frame data // Disable event handler registrations for events you are not using this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady; this.sensor.AllFramesReady += this.SensorAllFramesReady; this.sensor.ColorFrameReady += this.SensorColorFrameReady; this.sensor.DepthFrameReady += this.SensorDepthFrameReady; // Prepare the image byte buffer and the bitmap pixel buffer, then bind the bitmap to the WPF Image canvas this.pixelBytes = new byte[this.sensor.ColorStream.FramePixelDataLength]; this.colorBitmap = new WriteableBitmap(this.sensor.ColorStream.FrameWidth, this.sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null); Canvas.Source = colorBitmap; // Start the sensor! try { this.sensor.Start(); } catch (IOException) { this.sensor = null; } } // No sensor, complain if (null == this.sensor) { this.statusBarText.Text = Properties.Resources.NoKinectReady; } }
public DrawingGroupGuidelineSetExample() { // // Create a DrawingGroup // that has no guideline set // GeometryDrawing drawing1 = new GeometryDrawing( Brushes.Black, null, new RectangleGeometry(new Rect(0, 20, 30, 80)) ); GeometryGroup whiteRectangles = new GeometryGroup(); whiteRectangles.Children.Add(new RectangleGeometry(new Rect(5.5, 25, 20, 20))); whiteRectangles.Children.Add(new RectangleGeometry(new Rect(5.5, 50, 20, 20))); whiteRectangles.Children.Add(new RectangleGeometry(new Rect(5.5, 75, 20, 20))); GeometryDrawing drawing2 = new GeometryDrawing( Brushes.White, null, whiteRectangles ); // Create a DrawingGroup DrawingGroup drawingGroupWithoutGuidelines = new DrawingGroup(); drawingGroupWithoutGuidelines.Children.Add(drawing1); drawingGroupWithoutGuidelines.Children.Add(drawing2); // Use an Image control and a DrawingImage to // display the drawing. DrawingImage drawingImage01 = new DrawingImage(drawingGroupWithoutGuidelines); // Freeze the DrawingImage for performance benefits. drawingImage01.Freeze(); Image image01 = new Image(); image01.Source = drawingImage01; image01.Stretch = Stretch.None; image01.HorizontalAlignment = HorizontalAlignment.Left; image01.Margin = new Thickness(10); // // Create another DrawingGroup and apply // a blur effect to it. // // Create a clone of the first DrawingGroup. DrawingGroup drawingGroupWithGuidelines = drawingGroupWithoutGuidelines.Clone(); // Create a guideline set. GuidelineSet guidelines = new GuidelineSet(); guidelines.GuidelinesX.Add(5.5); guidelines.GuidelinesX.Add(25.5); guidelines.GuidelinesY.Add(25); guidelines.GuidelinesY.Add(50); guidelines.GuidelinesY.Add(75); // Apply it to the drawing group. drawingGroupWithGuidelines.GuidelineSet = guidelines; // Use another Image control and DrawingImage // to display the drawing. DrawingImage drawingImage02 = new DrawingImage(drawingGroupWithGuidelines); // Freeze the DrawingImage for performance benefits. drawingImage02.Freeze(); Image image02 = new Image(); image02.Source = drawingImage02; image02.Stretch = Stretch.None; image02.HorizontalAlignment = HorizontalAlignment.Left; image02.Margin = new Thickness(50, 10, 10, 10); StackPanel mainPanel = new StackPanel(); mainPanel.Orientation = Orientation.Horizontal; mainPanel.HorizontalAlignment = HorizontalAlignment.Left; mainPanel.Margin = new Thickness(20); mainPanel.Children.Add(image01); mainPanel.Children.Add(image02); // // Use a DrawingBrush to create a grid background. // GeometryDrawing backgroundRectangleDrawing = new GeometryDrawing( Brushes.White, null, new RectangleGeometry(new Rect(0, 0, 1, 1)) ); PolyLineSegment backgroundLine1 = new PolyLineSegment(); backgroundLine1.Points.Add(new Point(1, 0)); backgroundLine1.Points.Add(new Point(1, 0.1)); backgroundLine1.Points.Add(new Point(0, 0.1)); PathFigure line1Figure = new PathFigure(); line1Figure.Segments.Add(backgroundLine1); PathGeometry backgroundLine1Geometry = new PathGeometry(); backgroundLine1Geometry.Figures.Add(line1Figure); GeometryDrawing backgroundLineDrawing1 = new GeometryDrawing( new SolidColorBrush(Color.FromArgb(255, 204, 204, 255)), null, backgroundLine1Geometry ); PolyLineSegment backgroundLine2 = new PolyLineSegment(); backgroundLine2.Points.Add(new Point(0, 1)); backgroundLine2.Points.Add(new Point(0.1, 1)); backgroundLine2.Points.Add(new Point(0.1, 0)); PathFigure line2Figure = new PathFigure(); line2Figure.Segments.Add(backgroundLine2); PathGeometry backgroundLine2Geometry = new PathGeometry(); backgroundLine2Geometry.Figures.Add(line2Figure); GeometryDrawing backgroundLineDrawing2 = new GeometryDrawing( new SolidColorBrush(Color.FromArgb(255, 204, 204, 255)), null, backgroundLine2Geometry ); DrawingGroup backgroundGroup = new DrawingGroup(); backgroundGroup.Children.Add(backgroundRectangleDrawing); backgroundGroup.Children.Add(backgroundLineDrawing1); backgroundGroup.Children.Add(backgroundLineDrawing2); DrawingBrush gridPatternBrush = new DrawingBrush(backgroundGroup); gridPatternBrush.Viewport = new Rect(0, 0, 10, 10); gridPatternBrush.ViewportUnits = BrushMappingMode.Absolute; gridPatternBrush.TileMode = TileMode.Tile; gridPatternBrush.Freeze(); Border mainBorder = new Border(); mainBorder.Background = gridPatternBrush; mainBorder.BorderThickness = new Thickness(1); mainBorder.BorderBrush = Brushes.Gray; mainBorder.HorizontalAlignment = HorizontalAlignment.Left; mainBorder.VerticalAlignment = VerticalAlignment.Top; mainBorder.Margin = new Thickness(20); mainBorder.Child = mainPanel; // // Add the items to the page. // this.Content = mainBorder; this.Background = Brushes.White; }
/// <summary> /// Initialize the skeleton image to draw later /// </summary> private void InitializePart_DrawingSkeletonHandler() { // get the depth (display) extents FrameDescription frameDescription = kinectSensor.DepthFrameSource.FrameDescription; // get size of joint space this.displayWidth = frameDescription.Width; this.displayHeight = frameDescription.Height; // a bone defined as a line between two joints this.bones = new List <Tuple <JointType, JointType> >(); // Torso this.bones.Add(new Tuple <JointType, JointType>(JointType.Head, JointType.Neck)); this.bones.Add(new Tuple <JointType, JointType>(JointType.Neck, JointType.SpineShoulder)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.SpineMid)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineMid, JointType.SpineBase)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipLeft)); // Right Arm this.bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderRight, JointType.ElbowRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.ElbowRight, JointType.WristRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.HandRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.HandRight, JointType.HandTipRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.ThumbRight)); // Left Arm this.bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderLeft, JointType.ElbowLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.ElbowLeft, JointType.WristLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.HandLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.HandLeft, JointType.HandTipLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.ThumbLeft)); // Right Leg this.bones.Add(new Tuple <JointType, JointType>(JointType.HipRight, JointType.KneeRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.KneeRight, JointType.AnkleRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.AnkleRight, JointType.FootRight)); // Left Leg this.bones.Add(new Tuple <JointType, JointType>(JointType.HipLeft, JointType.KneeLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.KneeLeft, JointType.AnkleLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.AnkleLeft, JointType.FootLeft)); // populate body colors, one for each BodyIndex this.bodyColors = new List <Pen>(); this.bodyColors.Add(new Pen(Brushes.Red, 6)); this.bodyColors.Add(new Pen(Brushes.Orange, 6)); this.bodyColors.Add(new Pen(Brushes.Green, 6)); this.bodyColors.Add(new Pen(Brushes.Blue, 6)); this.bodyColors.Add(new Pen(Brushes.Indigo, 6)); this.bodyColors.Add(new Pen(Brushes.Violet, 6)); // Create the drawing group we'll use for drawing this.drawingGroup = new DrawingGroup(); // Create an image source that we can use in our image control this.skeletonImageSource = new DrawingImage(this.drawingGroup); }
private void InitWindowObjectAsViewModel() { this.imageSource = this.kinectCanvas.GetDrawingImage(); this.DataContext = this; this.InitializeComponent(); }
public static Image drawingSawtoothWave() { PathSegmentCollection pathSegmentCollection = new PathSegmentCollection(); PathFigureCollection segmentPathFigureCollection = new PathFigureCollection(); PathFigure segmentPathFigure = new PathFigure(); segmentPathFigure = new PathFigure(); segmentPathFigure.IsFilled = false; segmentPathFigure.IsClosed = false; Point StartPoint = new Point(0, 20); Point point1 = new Point(20, 0); Point point2 = new Point(20, 20); segmentPathFigure.StartPoint = StartPoint; LineSegment lineSegment1 = new LineSegment(point1, true); LineSegment lineSegment2 = new LineSegment(point2, true); pathSegmentCollection.Add(lineSegment1); pathSegmentCollection.Add(lineSegment2); segmentPathFigure.Segments = pathSegmentCollection; segmentPathFigureCollection.Add(segmentPathFigure); PathGeometry segmentPathGeometry = new PathGeometry(); segmentPathGeometry.Figures = segmentPathFigureCollection; // // Create the Geometry to draw. // GeometryGroup geometryGroup = new GeometryGroup(); geometryGroup.Children.Add(segmentPathGeometry); // // Create a GeometryDrawing. // GeometryDrawing aGeometryDrawing = new GeometryDrawing(); aGeometryDrawing.Geometry = geometryGroup; // Paint the drawing with a gradient. aGeometryDrawing.Brush = new LinearGradientBrush( Colors.Blue, Color.FromRgb(204, 204, 255), new Point(0, 0), new Point(1, 1)); // Outline the drawing with a solid color. aGeometryDrawing.Pen = new Pen(Brushes.Black, 2); // // Use a DrawingImage and an Image control // to display the drawing. // DrawingImage geometryImage = new DrawingImage(aGeometryDrawing); // Freeze the DrawingImage for performance benefits. geometryImage.Freeze(); Image anImage = new Image(); anImage.Source = geometryImage; anImage.HorizontalAlignment = HorizontalAlignment.Left; return(anImage); }
protected override void Write([NotNull] WpfRenderer renderer, [NotNull] MathBlock obj) { string text = string.Empty; // obj.Content.Text.Substring(obj.Content.Start, obj.Content.Length); for (int i = 0; i < obj.Lines.Count; ++i) { var l = obj.Lines.Lines[i]; text += l.Slice.Text.Substring(l.Slice.Start, l.Slice.Length); } if (string.IsNullOrEmpty(text)) { return; } TexFormula formula = null; try { formula = formulaParser.Parse(text); } catch (Exception) { var paragraph = new Paragraph() { Tag = obj }; renderer.Push(paragraph); renderer.WriteInline(new Run("[!!FORMULA PARSE ERROR!!]") { Tag = obj }); renderer.Pop(); return; } var fontSize = renderer.CurrentFontSize(); if (fontSize <= 0) { throw new InvalidProgramException(); } var formulaRenderer = formula.GetRenderer(TexStyle.Display, fontSize, "Arial"); var geo = formulaRenderer.RenderToGeometry(0, 0); var geoD = new System.Windows.Media.GeometryDrawing(Brushes.Black, null, geo); var di = new DrawingImage(geoD); var uiImage = new System.Windows.Controls.Image() { Source = di }; uiImage.Height = formulaRenderer.RenderSize.Height; // size image to match rendersize -> get a zoom of 100% // uiImage.Margin = new System.Windows.Thickness(0, 0, 0, -formulaRenderer.RenderSize.Height * formulaRenderer.RelativeDepth); // Move image so that baseline matches that of text var uiBlock = new System.Windows.Documents.BlockUIContainer() { Child = uiImage, Tag = obj, }; renderer.WriteBlock(uiBlock); }
public MainWindow() { this.kinectSensor = KinectSensor.GetDefault(); this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader(); this.colorFrameReader.FrameArrived += this.Read_ColorFrameArrived; FrameDescription colorframeDescription = this.kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); FrameDescription frameDescription = this.kinectSensor.DepthFrameSource.FrameDescription; this.colorBitmap = new WriteableBitmap(colorframeDescription.Width, colorframeDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null); // --------------------------------- this.coordinateMapper = kinectSensor.CoordinateMapper; this.displayWidth = frameDescription.Width; this.displayHeight = frameDescription.Height; this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader(); this.bodyFrameReader.FrameArrived += this.Read_BodyFrameArrived; if (this.bones != null) { this.bones.Add(new Tuple <JointType, JointType>(JointType.Head, JointType.Neck)); this.bones.Add(new Tuple <JointType, JointType>(JointType.Neck, JointType.SpineShoulder)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.SpineMid)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineMid, JointType.SpineBase)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderRight, JointType.ElbowRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.ElbowRight, JointType.WristRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.HandRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.HandRight, JointType.HandTipRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.ThumbRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderLeft, JointType.ElbowLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.ElbowLeft, JointType.WristLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.HandLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.HandLeft, JointType.HandTipLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.ThumbLeft)); } this.bodyColors = new List <Pen>(); this.bodyColors.Add(new Pen(Brushes.Red, 6)); this.bodyColors.Add(new Pen(Brushes.Orange, 6)); this.bodyColors.Add(new Pen(Brushes.Green, 6)); this.bodyColors.Add(new Pen(Brushes.Blue, 6)); this.bodyColors.Add(new Pen(Brushes.Indigo, 6)); this.bodyColors.Add(new Pen(Brushes.Violet, 6)); this.kinectSensor.Open(); this.drawingGroup = new DrawingGroup(); this.imageSource = new DrawingImage(this.drawingGroup); this.DataContext = this; //이게들어가야 데이터를 가져올 수 있다.(kinect에서) InitializeComponent(); }
/// <summary> /// Execute startup tasks /// </summary> /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> private void WindowLoaded(object sender, RoutedEventArgs e) { brush = Brushes.White; // Create the drawing group we'll use for drawing this.drawingGroup = new DrawingGroup(); // Create an image source that we can use in our image control this.imageSource = new DrawingImage(this.drawingGroup); // Display the drawing using our image control Image.Source = this.imageSource; // Look through all sensors and start the first connected one. // This requires that a Kinect is connected at the time of app startup. // To make your app robust against plug/unplug, // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit (See components in Toolkit Browser). foreach (var potentialSensor in KinectSensor.KinectSensors) { if (potentialSensor.Status == KinectStatus.Connected) { this.sensor = potentialSensor; break; } } if (null != this.sensor) { // Turn on the skeleton stream to receive skeleton frames this.sensor.SkeletonStream.Enable(); // Add an event handler to be called whenever there is new color frame data this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady; // Start the sensor! try { this.sensor.Start(); } catch (IOException) { this.sensor = null; } } if (null == this.sensor) { this.statusBarText.Text = "Connect Kinect and try again"; return; } //For audio recogninzer RecognizerInfo ri = (from recognizer in SpeechRecognitionEngine.InstalledRecognizers() where "en-US".Equals(recognizer.Culture.Name, StringComparison.OrdinalIgnoreCase) select recognizer).FirstOrDefault(); if (ri != null) { this.speechEngine = new SpeechRecognitionEngine(ri.Id); //var fontsizes = new Choices(); //fontsizes.Add(new SemanticResultValue("SMALL", "Small")); //fontsizes.Add(new SemanticResultValue("MEDIUM", "Medium")); //fontsizes.Add(new SemanticResultValue("LARGE", "Large")); //gb.Append(fontsizes); var colors = new Choices(); colors.Add("yellow"); colors.Add("red"); colors.Add("pink"); colors.Add("green"); //colors.Add("quit"); //var quit = new Choices(); //quit.Add("quit"); var gb = new GrammarBuilder(); gb.Culture = ri.Culture; gb.Append(colors); //gb.Append(quit); var g = new Grammar(gb); speechEngine.LoadGrammar(g); this.speechEngine.SpeechRecognized += new EventHandler <SpeechRecognizedEventArgs>(speechEngine_SpeechRecognized); speechEngine.SetInputToAudioStream(sensor.AudioSource.Start(), new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null)); speechEngine.RecognizeAsync(RecognizeMode.Multiple); var q = new GrammarBuilder(); q.Append("quit"); var quit = new Grammar(q); speechEngine.LoadGrammar(quit); } }
private void WindowLoaded(object sender, RoutedEventArgs e) { xmppClient = new XmppClient { // Ingresar credenciales de acceso aquí XmppDomain = "xmpp.binarylamp.cl", Username = "******", Password = "******", Resource = "test" }; xmppClient.OnMessage += XmppClient_OnMessage; xmppClient.Open(); timer.Enabled = true; timer.Interval = 1500; timer.Elapsed += new System.Timers.ElapsedEventHandler(timerElapsedTime); // Create the drawing group we'll use for drawing this.drawingGroup = new DrawingGroup(); // Create an image source that we can use in our image control this.imageSource = new DrawingImage(this.drawingGroup); // Display the drawing using our image control Image.Source = this.imageSource; // Look through all sensors and start the first connected one. // This requires that a Kinect is connected at the time of app startup. // To make your app robust against plug/unplug, // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit (See components in Toolkit Browser). foreach (var potentialSensor in KinectSensor.KinectSensors) { if (potentialSensor.Status == KinectStatus.Connected) { this.sensor = potentialSensor; break; } } if (null != this.sensor) { // Turn on the skeleton stream to receive skeleton frames this.sensor.SkeletonStream.Enable(); // Add an event handler to be called whenever there is new color frame data this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady; // Start the sensor! try { this.sensor.Start(); } catch (IOException) { this.sensor = null; } } if (null == this.sensor) { this.statusBarText.Text = Properties.Resources.NoKinectReady; } }
public override void Render(WpfDrawingRenderer renderer) { WpfDrawingContext context = renderer.Context; SvgImageElement imageElement = (SvgImageElement)_svgElement; double width = imageElement.Width.AnimVal.Value; double height = imageElement.Height.AnimVal.Value; Rect destRect = new Rect(imageElement.X.AnimVal.Value, imageElement.Y.AnimVal.Value, width, height); ImageSource imageSource = null; if (imageElement.IsSvgImage) { SvgWindow wnd = GetSvgWindow(); //_embeddedRenderer.BackColor = Color.Empty; _embeddedRenderer.Render(wnd.Document); DrawingGroup imageGroup = _embeddedRenderer.Drawing as DrawingGroup; if (imageGroup != null && (imageGroup.Children != null && imageGroup.Children.Count == 1)) { DrawingGroup drawImage = imageGroup.Children[0] as DrawingGroup; if (drawImage != null) { if (drawImage.ClipGeometry != null) { drawImage.ClipGeometry = null; } imageSource = new DrawingImage(drawImage); } else { if (imageGroup.ClipGeometry != null) { imageGroup.ClipGeometry = null; } imageSource = new DrawingImage(imageGroup); } } else { imageSource = new DrawingImage(_embeddedRenderer.Drawing); } if (_embeddedRenderer != null) { _embeddedRenderer.Dispose(); _embeddedRenderer = null; } } else { imageSource = GetBitmapSource(imageElement, context); } if (imageSource == null) { return; } //TODO--PAUL: Set the DecodePixelWidth/DecodePixelHeight? // Freeze the DrawingImage for performance benefits. imageSource.Freeze(); DrawingGroup drawGroup = null; ISvgAnimatedPreserveAspectRatio animatedAspectRatio = imageElement.PreserveAspectRatio; if (animatedAspectRatio != null && animatedAspectRatio.AnimVal != null) { SvgPreserveAspectRatio aspectRatio = animatedAspectRatio.AnimVal as SvgPreserveAspectRatio; SvgPreserveAspectRatioType aspectRatioType = (aspectRatio != null) ? aspectRatio.Align : SvgPreserveAspectRatioType.Unknown; if (aspectRatio != null && aspectRatioType != SvgPreserveAspectRatioType.None && aspectRatioType != SvgPreserveAspectRatioType.Unknown) { double imageWidth = imageSource.Width; double imageHeight = imageSource.Height; double viewWidth = destRect.Width; double viewHeight = destRect.Height; SvgMeetOrSlice meetOrSlice = aspectRatio.MeetOrSlice; if (meetOrSlice == SvgMeetOrSlice.Meet) { if (imageWidth <= viewWidth && imageHeight <= viewHeight) { destRect = this.GetBounds(destRect, new Size(imageWidth, imageHeight), aspectRatioType); } else { Transform viewTransform = this.GetAspectRatioTransform(aspectRatio, new SvgRect(0, 0, imageWidth, imageHeight), new SvgRect(destRect.X, destRect.Y, destRect.Width, destRect.Height)); //Transform scaleTransform = this.FitToViewbox(aspectRatio, // new SvgRect(destRect.X, destRect.Y, imageWidth, imageHeight), // new SvgRect(destRect.X, destRect.Y, destRect.Width, destRect.Height)); if (viewTransform != null) { drawGroup = new DrawingGroup(); drawGroup.Transform = viewTransform; DrawingGroup lastGroup = context.Peek(); Debug.Assert(lastGroup != null); if (lastGroup != null) { lastGroup.Children.Add(drawGroup); } destRect = this.GetBounds(destRect, new Size(imageWidth, imageHeight), aspectRatioType); // The origin is already handled by the view transform... destRect.X = 0; destRect.Y = 0; } } } else if (meetOrSlice == SvgMeetOrSlice.Slice) { } } } ImageDrawing drawing = new ImageDrawing(imageSource, destRect); float opacityValue = -1; string opacity = imageElement.GetAttribute("opacity"); if (opacity != null && opacity.Length > 0) { opacityValue = (float)SvgNumber.ParseNumber(opacity); opacityValue = Math.Min(opacityValue, 1); opacityValue = Math.Max(opacityValue, 0); } Geometry clipGeom = this.ClipGeometry; Transform transform = this.Transform; if (drawGroup == null) { drawGroup = context.Peek(); } Debug.Assert(drawGroup != null); if (drawGroup != null) { if (opacityValue >= 0 || (clipGeom != null && !clipGeom.IsEmpty()) || (transform != null && !transform.Value.IsIdentity)) { DrawingGroup clipGroup = new DrawingGroup(); if (opacityValue >= 0) { clipGroup.Opacity = opacityValue; } if (clipGeom != null) { SvgUnitType clipUnits = this.ClipUnits; if (clipUnits == SvgUnitType.ObjectBoundingBox) { Rect drawingBounds = drawing.Bounds; TransformGroup transformGroup = new TransformGroup(); // Scale the clip region (at (0, 0)) and translate to the top-left corner of the target. transformGroup.Children.Add( new ScaleTransform(drawingBounds.Width, drawingBounds.Height)); transformGroup.Children.Add( new TranslateTransform(drawingBounds.X, drawingBounds.Y)); clipGeom.Transform = transformGroup; } clipGroup.ClipGeometry = clipGeom; } if (transform != null) { clipGroup.Transform = transform; } clipGroup.Children.Add(drawing); drawGroup.Children.Add(clipGroup); } else { drawGroup.Children.Add(drawing); } } }
private void Initialize() { this.kinect = KinectSensor.GetDefault(); if (kinect == null) { return; } this.coordinateMapper = this.kinect.CoordinateMapper; // open the reader for the color frames this.colorFrameReader = this.kinect.ColorFrameSource.OpenReader(); // wire handler for frame arrival this.colorFrameReader.FrameArrived += this.Reader_ColorFrameArrived; // create the colorFrameDescription from the ColorFrameSource using Bgra format FrameDescription frameDescription = this.kinect.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); // for image / video save uint frameSize = frameDescription.BytesPerPixel * frameDescription.LengthInPixels; this.colorData = new byte[frameSize]; // create the bitmap to display this.colorBitmap = new WriteableBitmap(frameDescription.Width, frameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null); // set the display specifics this.displayWidth = frameDescription.Width; this.displayHeight = frameDescription.Height; this.displayRect = new Rect(0.0, 0.0, this.displayWidth, this.displayHeight); // open the reader for the body frames this.bodyFrameReader = this.kinect.BodyFrameSource.OpenReader(); // wire handler for body frame arrival this.bodyFrameReader.FrameArrived += this.Reader_BodyFrameArrived; // set the maximum number of bodies that would be tracked by Kinect this.bodyCount = this.kinect.BodyFrameSource.BodyCount; this.hdFaceFrameSources = new HighDefinitionFaceFrameSource(this.kinect); // create the face frame source with the required face frame features and an initial tracking Id of 0 this.faceFrameSource = new FaceFrameSource(this.kinect, 0, FaceFrameFeatures.LeftEyeClosed | FaceFrameFeatures.RightEyeClosed | FaceFrameFeatures.MouthOpen | FaceFrameFeatures.MouthMoved | FaceFrameFeatures.Glasses | FaceFrameFeatures.FaceEngagement | FaceFrameFeatures.LookingAway | FaceFrameFeatures.Happy | FaceFrameFeatures.PointsInColorSpace | FaceFrameFeatures.BoundingBoxInColorSpace); this.faceFrameReaders = this.faceFrameSource.OpenReader(); this.hdFaceFrameSources = new HighDefinitionFaceFrameSource(this.kinect); // open the corresponding reader this.faceFrameReaders = this.faceFrameSource.OpenReader(); this.hdFaceFrameReaders = this.hdFaceFrameSources.OpenReader(); this.faceModel = new FaceModel(); this.faceAlignment = new FaceAlignment(); // initialize the components (controls) of the window //this.InitializeComponent(); // populate face result colors = one for each face index this.faceBrush = Brushes.White; this.kinect.Open(); // Create the drawing group we'll use for drawing this.drawingGroup = new DrawingGroup(); // Create an image source that we can use in our iamge control this.imageSource = new DrawingImage(this.drawingGroup); this.an = new BitmapImage(new Uri("C:/Users/Kyoungsoo Park/Desktop/client2/Demo/Demo/Images/Emoticon/Anger.png", UriKind.Relative)); this.fe = new BitmapImage(new Uri("C:/Users/Kyoungsoo Park/Desktop/client2/Demo/Demo/Images/Emoticon/Fear.png", UriKind.Relative)); this.ha = new BitmapImage(new Uri("C:/Users/Kyoungsoo Park/Desktop/client2/Demo/Demo/Images/Emoticon/happy.png", UriKind.Relative)); this.ne = new BitmapImage(new Uri("C:/Users/Kyoungsoo Park/Desktop/client2/Demo/Demo/Images/Emoticon/Neutral.png", UriKind.Relative)); this.sa = new BitmapImage(new Uri("C:/Users/Kyoungsoo Park/Desktop/client2/Demo/Demo/Images/Emoticon/Sad.png", UriKind.Relative)); this.su = new BitmapImage(new Uri("C:/Users/Kyoungsoo Park/Desktop/client2/Demo/Demo/Images/Emoticon/Surprise.png", UriKind.Relative)); SeriesCollection = new SeriesCollection { new RowSeries { Title = "Predict Probability", Values = new ChartValues <double> { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }, DataLabels = true } }; SeriesCollection[0].OnSeriesUpdateStart(); Labels = new[] { "Neutral", "Fear", "Happy", "Angry", "Sad", "Surpirse" }; //Labels = new[] { "Joy", "Calm", "Sad", "Stress" }; //Labels = tempDict.Keys.ToArray(); Formatter = value => value.ToString("P"); // object init this._lock = new Object(); // Socket Communication this.client = new Client("advice.hufs.ac.kr", 50001); }
/// <summary> /// Execute startup tasks /// </summary> /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> private void WindowLoaded(object sender, RoutedEventArgs e) { // Create the drawing group we'll use for drawing this.drawingGroup = new DrawingGroup(); // Create an image source that we can use in our image control this.imageSource = new DrawingImage(this.drawingGroup); // Display the drawing using our image control Image.Source = this.imageSource; KeyUp += Window_OpenDebug; SensorSkeletonFrameReady(null, null); // Look through all sensors and start the first connected one. // This requires that a Kinect is connected at the time of app startup. // To make your app robust against plug/unplug, // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit (See components in Toolkit Browser). foreach (var potentialSensor in KinectSensor.KinectSensors) { if (potentialSensor.Status == KinectStatus.Connected) { this.sensor = potentialSensor; break; } } if (null != this.sensor) { // Turn on the skeleton stream to receive skeleton frames this.sensor.SkeletonStream.Enable(); // Start the sensor! try { this.sensor.Start(); } catch (IOException) { this.sensor = null; } PropertyChanged += CalibrationChanged; CalibrationStep = CalibrationStep.NotCalibrated; } if (null != this.sensor) { // Setup calibrator to receive mappings between reality and screen image this.calibrationClass = new CalibrationClass(this.sensor); // Listen for key to advance the calibration process. KeyUp += Window_Calibrate; KeyUp += Window_AutoCalibrate; KeyUp += Window_Reset; } if (null == this.sensor) { this.statusBarText.Text = Properties.Resources.NoKinectReady; } }
public TransformExample() { // // Create a GeometryDrawing. // // Define the drawing's contents. PathFigure pLineFigure = new PathFigure(); pLineFigure.StartPoint = new Point(25, 25); PolyLineSegment pLineSegment = new PolyLineSegment(); pLineSegment.Points.Add(new Point(0, 50)); pLineSegment.Points.Add(new Point(25, 75)); pLineSegment.Points.Add(new Point(50, 50)); pLineSegment.Points.Add(new Point(25, 25)); pLineSegment.Points.Add(new Point(25, 0)); pLineFigure.Segments.Add(pLineSegment); PathGeometry pGeometry = new PathGeometry(); pGeometry.Figures.Add(pLineFigure); GeometryDrawing drawing1 = new GeometryDrawing( Brushes.Lime, new Pen(Brushes.Black, 10), pGeometry ); // // Create another GeometryDrawing. // GeometryDrawing drawing2 = new GeometryDrawing( Brushes.Lime, new Pen(Brushes.Black, 2), new EllipseGeometry(new Point(10, 10), 5, 5) ); // Create the DrawingGroup and add the // geometry drawings. DrawingGroup aDrawingGroup = new DrawingGroup(); aDrawingGroup.Children.Add(drawing1); aDrawingGroup.Children.Add(drawing2); // // Create a RotateTransform and apply it to the // drawing group. // RotateTransform rotation = new RotateTransform( 45, // Angle 50, // CenterX 75 // CenterY ); aDrawingGroup.Transform = rotation; // Use an Image control and a DrawingImage to // display the drawing. DrawingImage aDrawingImage = new DrawingImage(aDrawingGroup); // Freeze the DrawingImage for performance benefits. aDrawingImage.Freeze(); Image anImage = new Image(); anImage.Source = aDrawingImage; anImage.Stretch = Stretch.None; anImage.HorizontalAlignment = HorizontalAlignment.Left; // Create a border around the images and add it to the // page. Border imageBorder = new Border(); imageBorder.BorderBrush = Brushes.Gray; imageBorder.BorderThickness = new Thickness(1); imageBorder.VerticalAlignment = VerticalAlignment.Top; imageBorder.HorizontalAlignment = HorizontalAlignment.Left; imageBorder.Margin = new Thickness(20); imageBorder.Child = anImage; this.Background = Brushes.White; this.Margin = new Thickness(20); this.Content = imageBorder; }
public static DrawingImage CreateImage(PointPattern[] pointPatterns, Size size, Color color) { if (pointPatterns == null) { return(null); } DrawingGroup drawingGroup = new DrawingGroup(); for (int i = 0; i < pointPatterns.Length; i++) { PathGeometry pathGeometry = new PathGeometry(); color.A = (byte)(0xFF - i * 0x55); SolidColorBrush brush = new SolidColorBrush(color); Pen drawingPen = new Pen(brush, size.Height / 20 + i * 1.5) { StartLineCap = PenLineCap.Round, EndLineCap = PenLineCap.Round }; if (pointPatterns[i].Points == null) { return(null); } for (int j = 0; j < pointPatterns[i].Points.Count; j++) { if (pointPatterns[i].Points[j].Count == 1) { Geometry ellipse = new EllipseGeometry(new Point(size.Width * j + size.Width / 2, size.Height / 2), drawingPen.Thickness / 2, drawingPen.Thickness / 2); pathGeometry.AddGeometry(ellipse); continue; } StreamGeometry sg = new StreamGeometry { FillRule = FillRule.EvenOdd }; using (StreamGeometryContext sgc = sg.Open()) { // Create new size object accounting for pen width Size szeAdjusted = new Size(size.Width - drawingPen.Thickness - 1, (size.Height - drawingPen.Thickness - 1)); Size scaledSize; Point[] scaledPoints = ScaleGesture(pointPatterns[i].Points[j], szeAdjusted.Width - 10, szeAdjusted.Height - 10, out scaledSize); // Define size that will mark the offset to center the gesture double iLeftOffset = (size.Width / 2) - (scaledSize.Width / 2); double iTopOffset = (size.Height / 2) - (scaledSize.Height / 2); Vector sizOffset = new Vector(iLeftOffset + j * size.Width, iTopOffset); sgc.BeginFigure(Point.Add(scaledPoints[0], sizOffset), false, false); foreach (Point p in scaledPoints) { sgc.LineTo(Point.Add(p, sizOffset), true, true); } DrawArrow(sgc, scaledPoints, sizOffset, drawingPen.Thickness); } sg.Freeze(); pathGeometry.AddGeometry(sg); } pathGeometry.Freeze(); GeometryDrawing drawing = new GeometryDrawing(null, drawingPen, pathGeometry); drawing.Freeze(); drawingGroup.Children.Add(drawing); } // myPath.Data = sg; drawingGroup.Freeze(); DrawingImage drawingImage = new DrawingImage(drawingGroup); drawingImage.Freeze(); return(drawingImage); }
/// <summary> /// Initializes a new instance of the MainWindow class. /// </summary> public MainWindow() { //Added, JN 01.2020 #if DEBUG ConsoleManager.Show(); #endif // one sensor is currently supported this.kinectSensor = KinectSensor.GetDefault(); // get the coordinate mapper this.coordinateMapper = this.kinectSensor.CoordinateMapper; // open the reader for the color frames this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader(); // wire handler for frame arrival this.colorFrameReader.FrameArrived += this.Reader_ColorFrameArrived; // create the colorFrameDescription from the ColorFrameSource using Bgra format FrameDescription colorFrameDescription = this.kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); // create the bitmap to display this.colorBitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null); // get the depth (display) extents FrameDescription frameDescription = this.kinectSensor.DepthFrameSource.FrameDescription; //dirty hack for camera frame mapping trackingWidth = 1200; //1296 trackingHeight = 1080; // get size of joint space this.displayWidth = colorFrameDescription.Width; this.displayHeight = colorFrameDescription.Height; // open the reader for the body frames this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader(); // a bone defined as a line between two joints this.bones = new List <Tuple <JointType, JointType> >(); // Torso this.bones.Add(new Tuple <JointType, JointType>(JointType.Head, JointType.Neck)); this.bones.Add(new Tuple <JointType, JointType>(JointType.Neck, JointType.SpineShoulder)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.SpineMid)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineMid, JointType.SpineBase)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipLeft)); // Right Arm this.bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderRight, JointType.ElbowRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.ElbowRight, JointType.WristRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.HandRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.HandRight, JointType.HandTipRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.ThumbRight)); // Left Arm this.bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderLeft, JointType.ElbowLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.ElbowLeft, JointType.WristLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.HandLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.HandLeft, JointType.HandTipLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.ThumbLeft)); // Right Leg this.bones.Add(new Tuple <JointType, JointType>(JointType.HipRight, JointType.KneeRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.KneeRight, JointType.AnkleRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.AnkleRight, JointType.FootRight)); // Left Leg this.bones.Add(new Tuple <JointType, JointType>(JointType.HipLeft, JointType.KneeLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.KneeLeft, JointType.AnkleLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.AnkleLeft, JointType.FootLeft)); // populate body colors, one for each BodyIndex this.bodyColors = new List <Pen>(); this.bodyColors.Add(new Pen(Brushes.Red, 6)); this.bodyColors.Add(new Pen(Brushes.Orange, 6)); this.bodyColors.Add(new Pen(Brushes.Green, 6)); this.bodyColors.Add(new Pen(Brushes.Blue, 6)); this.bodyColors.Add(new Pen(Brushes.Indigo, 6)); this.bodyColors.Add(new Pen(Brushes.Violet, 6)); // set IsAvailableChanged event notifier this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged; // open the sensor this.kinectSensor.Open(); // set the status text this.StatusText = this.kinectSensor.IsAvailable ? Properties.Resources.RunningStatusText : Properties.Resources.NoSensorStatusText; // Create the drawing group we'll use for drawing this.drawingGroup = new DrawingGroup(); //drawingGroup.Children.Add(new ImageDrawing(null, new Rect(0, 0, colorFrameDescription.Width, colorFrameDescription.Height))); // Create an image source that we can use in our image control this.imageSource = new DrawingImage(this.drawingGroup); // use the window object as the view model in this simple example this.DataContext = this; // initialize the components (controls) of the window this.InitializeComponent(); //json stuff - JN 12.2019 this.sb = new StringBuilder(); this.sw = new StringWriter(sb); this.writer = new JsonTextWriter(sw) { Formatting = Formatting.Indented }; this.JsonObject = new jsonObjects(); this.JsonObject.CaptureArea.widthColorFrame = this.displayWidth; this.JsonObject.CaptureArea.heightColorFrame = this.displayHeight; //position estimation is only 512 * 412 -> mapped to 1920 x 1080 this.JsonObject.CaptureArea.widthPoseData = 1296; this.JsonObject.CaptureArea.heightPoseData = 1080; }
public int degree; //BA /// <summary> /// Initializes a new instance of the MainWindow class. /// </summary> public MainWindow() { // one sensor is currently supported this.kinectSensor = KinectSensor.GetDefault(); // open the reader for the color frames BA this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader(); // wire handler for frame arrival BA this.colorFrameReader.FrameArrived += this.Reader_ColorFrameArrived; // get the coordinate mapper this.coordinateMapper = this.kinectSensor.CoordinateMapper; // get the color frame details BA //FrameDescription frameDescription = this.kinectSensor.ColorFrameSource.FrameDescription; FrameDescription frameDescription = this.kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); // BA create the colorFrameDescription from the ColorFrameSource using Bgra format FrameDescription colorFrameDescription = this.kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); // BA create the bitmap to display this.colorBitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null); // set the display specifics this.displayWidth = frameDescription.Width; this.displayHeight = frameDescription.Height; this.displayRect = new Rect(0.0, 0.0, this.displayWidth, this.displayHeight); // open the reader for the body frames this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader(); // wire handler for body frame arrival this.bodyFrameReader.FrameArrived += this.Reader_BodyFrameArrived; // set the maximum number of bodies that would be tracked by Kinect this.bodyCount = this.kinectSensor.BodyFrameSource.BodyCount; // allocate storage to store body objects this.bodies = new Body[this.bodyCount]; // specify the required face frame results FaceFrameFeatures faceFrameFeatures = FaceFrameFeatures.BoundingBoxInColorSpace | FaceFrameFeatures.PointsInColorSpace | FaceFrameFeatures.RotationOrientation | FaceFrameFeatures.FaceEngagement | FaceFrameFeatures.Glasses | FaceFrameFeatures.Happy | FaceFrameFeatures.LeftEyeClosed | FaceFrameFeatures.RightEyeClosed | FaceFrameFeatures.LookingAway | FaceFrameFeatures.MouthMoved | FaceFrameFeatures.MouthOpen; // create a face frame source + reader to track each face in the FOV this.faceFrameSources = new FaceFrameSource[this.bodyCount]; this.faceFrameReaders = new FaceFrameReader[this.bodyCount]; for (int i = 0; i < this.bodyCount; i++) { // create the face frame source with the required face frame features and an initial tracking Id of 0 this.faceFrameSources[i] = new FaceFrameSource(this.kinectSensor, 0, faceFrameFeatures); // open the corresponding reader this.faceFrameReaders[i] = this.faceFrameSources[i].OpenReader(); } // allocate storage to store face frame results for each face in the FOV this.faceFrameResults = new FaceFrameResult[this.bodyCount]; // populate face result colors - one for each face index this.faceBrush = new List <Brush>() { Brushes.White, Brushes.Orange, Brushes.Green, Brushes.Red, Brushes.LightBlue, Brushes.Yellow }; // set IsAvailableChanged event notifier this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged; // open the sensor this.kinectSensor.Open(); // set the status text this.StatusText = this.kinectSensor.IsAvailable ? Properties.Resources.RunningStatusText : Properties.Resources.NoSensorStatusText; // Create the drawing group we'll use for drawing this.drawingGroup = new DrawingGroup(); // Create an image source that we can use in our image control this.imageSource = new DrawingImage(this.drawingGroup); // use the window object as the view model in this simple example this.DataContext = this; // initialize the components (controls) of the window this.InitializeComponent(); }
public MainWindow() { #region Define bones // Torso bones.Add(new Tuple <JointType, JointType>(JointType.Head, JointType.Neck)); bones.Add(new Tuple <JointType, JointType>(JointType.Neck, JointType.SpineShoulder)); bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.SpineMid)); bones.Add(new Tuple <JointType, JointType>(JointType.SpineMid, JointType.SpineBase)); bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderRight)); bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderLeft)); bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipRight)); bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipLeft)); // Right Arm bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderRight, JointType.ElbowRight)); bones.Add(new Tuple <JointType, JointType>(JointType.ElbowRight, JointType.WristRight)); bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.HandRight)); bones.Add(new Tuple <JointType, JointType>(JointType.HandRight, JointType.HandTipRight)); bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.ThumbRight)); // Left Arm bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderLeft, JointType.ElbowLeft)); bones.Add(new Tuple <JointType, JointType>(JointType.ElbowLeft, JointType.WristLeft)); bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.HandLeft)); bones.Add(new Tuple <JointType, JointType>(JointType.HandLeft, JointType.HandTipLeft)); bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.ThumbLeft)); // Right Leg bones.Add(new Tuple <JointType, JointType>(JointType.HipRight, JointType.KneeRight)); bones.Add(new Tuple <JointType, JointType>(JointType.KneeRight, JointType.AnkleRight)); bones.Add(new Tuple <JointType, JointType>(JointType.AnkleRight, JointType.FootRight)); // Left Leg bones.Add(new Tuple <JointType, JointType>(JointType.HipLeft, JointType.KneeLeft)); bones.Add(new Tuple <JointType, JointType>(JointType.KneeLeft, JointType.AnkleLeft)); bones.Add(new Tuple <JointType, JointType>(JointType.AnkleLeft, JointType.FootLeft)); #endregion //Initialize mean filters meanFilterLeftX = new MeanFilter(meanFilterBufferSize); meanFilterLeftY = new MeanFilter(meanFilterBufferSize); meanFilterRightX = new MeanFilter(meanFilterBufferSize); meanFilterRightY = new MeanFilter(meanFilterBufferSize); //Initialize kinect kinectSensor = KinectSensor.GetDefault(); //Body tracker reader coordinateMapper = kinectSensor.CoordinateMapper; FrameDescription depthFrameDescription = kinectSensor.DepthFrameSource.FrameDescription; displayWidth = depthFrameDescription.Width; displayHeight = depthFrameDescription.Height; bodyFrameReader = kinectSensor.BodyFrameSource.OpenReader(); bodyFrameReader.FrameArrived += BodyFrameReader_FrameArrived; bodyDrawingGroup = new DrawingGroup(); bodyDrawingImage = new DrawingImage(bodyDrawingGroup); //Color camera reader colorFrameReader = kinectSensor.ColorFrameSource.OpenReader(); colorFrameReader.FrameArrived += ColorFrameReader_FrameArrived; FrameDescription colorFrameDescription = kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); colorBitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null); //Register events handler for availability change kinectSensor.IsAvailableChanged += KinectSensor_IsAvailableChanged; kinectSensor.Open(); //Initialize the components of the window InitializeComponent(); //Specify data context DataContext = this; dataGrid.DataContext = bodiesInfo; //Update baudrate combobox CmbBoxBaudRate.Items.Add(9600); CmbBoxBaudRate.Items.Add(19200); CmbBoxBaudRate.Items.Add(38400); CmbBoxBaudRate.Items.Add(57600); CmbBoxBaudRate.Items.Add(115200); CmbBoxBaudRate.SelectedIndex = 0; //Update ports combobox UpdatePortsList(); }
private void InvokeUpdateKeyboardPreview(object sender, ElapsedEventArgs e) { if (_blurProgress > 2) { _blurProgress = 0; } _blurProgress = _blurProgress + 0.025; BlurRadius = (Math.Sin(_blurProgress * Math.PI) + 1) * 10 + 10; if (SelectedProfile == null || _deviceManager.ActiveKeyboard == null) { var preview = new DrawingImage(); preview.Freeze(); KeyboardPreview = preview; return; } var keyboardRect = _deviceManager.ActiveKeyboard.KeyboardRectangle(4); var visual = new DrawingVisual(); using (var drawingContext = visual.RenderOpen()) { // Setup the DrawingVisual's size drawingContext.PushClip(new RectangleGeometry(keyboardRect)); drawingContext.DrawRectangle(new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)), null, keyboardRect); // Draw the layers var drawLayers = SelectedProfile.GetRenderLayers <ProfilePreviewDataModel>( new ProfilePreviewDataModel(), false, false, true); foreach (var layer in drawLayers) { layer.Draw(null, drawingContext, true, false); } // Get the selection color var accentColor = ThemeManager.DetectAppStyle(Application.Current)?.Item2?.Resources["AccentColor"]; if (accentColor == null) { return; } var pen = new Pen(new SolidColorBrush((Color)accentColor), 0.4); // Draw the selection outline and resize indicator if (SelectedLayer != null && SelectedLayer.MustDraw()) { var layerRect = ((KeyboardPropertiesModel)SelectedLayer.Properties).GetRect(); // Deflate the rect so that the border is drawn on the inside layerRect.Inflate(-0.2, -0.2); // Draw an outline around the selected layer drawingContext.DrawRectangle(null, pen, layerRect); // Draw a resize indicator in the bottom-right drawingContext.DrawLine(pen, new Point(layerRect.BottomRight.X - 1, layerRect.BottomRight.Y - 0.5), new Point(layerRect.BottomRight.X - 1.2, layerRect.BottomRight.Y - 0.7)); drawingContext.DrawLine(pen, new Point(layerRect.BottomRight.X - 0.5, layerRect.BottomRight.Y - 1), new Point(layerRect.BottomRight.X - 0.7, layerRect.BottomRight.Y - 1.2)); drawingContext.DrawLine(pen, new Point(layerRect.BottomRight.X - 0.5, layerRect.BottomRight.Y - 0.5), new Point(layerRect.BottomRight.X - 0.7, layerRect.BottomRight.Y - 0.7)); } // Remove the clip drawingContext.Pop(); } var drawnPreview = new DrawingImage(visual.Drawing); drawnPreview.Freeze(); KeyboardPreview = drawnPreview; }
private void CreateVisual(CaretAdornmentData nodeData, int caretLineOffset, int caretOffset, IUserIdentity userIdentity) { if (View.IsClosed) { return; } if (RepoDocument != null && nodeData.RelativeToServerSource) { var remoteFileText = SourceControlRepo.GetRemoteFileLines(View.TextBuffer.GetTextDocumentFilePath()); if (remoteFileText != null) { string localFileText = View.TextSnapshot.GetText(); caretLineOffset = LineNumberTranslator.GetLineNumber(localFileText.Split(new[] { "\r\n" }, StringSplitOptions.None), remoteFileText, caretLineOffset, FileNumberBasis.Local); } } var caretLineNumber = View.TextSnapshot.GetLineNumberFromPosition(nodeData.SpanStart) + caretLineOffset; var caretPosition = View.TextSnapshot.GetLineFromLineNumber(Math.Min(caretLineNumber, View.TextSnapshot.LineCount - 1)).Start.Position + caretOffset; if (caretPosition < nodeData.NonWhiteSpaceStart) { caretPosition = nodeData.NonWhiteSpaceStart; } else if (caretPosition > nodeData.SpanEnd) { caretPosition = nodeData.SpanEnd; } var atEnd = caretPosition >= View.TextSnapshot.Length; var remoteCaretSpan = new SnapshotSpan(View.TextSnapshot, atEnd ? View.TextSnapshot.Length - 1 : caretPosition, 1); var onSameLineAsEnd = remoteCaretSpan.Start.GetContainingLine().LineNumber == View.TextSnapshot.GetLineNumberFromPosition(View.TextSnapshot.Length); Geometry characterGeometry = View.TextViewLines.IsValid ? View.TextViewLines.GetMarkerGeometry(remoteCaretSpan) : null; if (characterGeometry != null) { var caretGeometry = new LineGeometry(atEnd && onSameLineAsEnd ? characterGeometry.Bounds.TopRight : characterGeometry.Bounds.TopLeft, atEnd && onSameLineAsEnd ? characterGeometry.Bounds.BottomRight : characterGeometry.Bounds.BottomLeft); var drawing = new GeometryDrawing(null, UserColours.GetUserPen(userIdentity), caretGeometry); drawing.Freeze(); var drawingImage = new DrawingImage(drawing); drawingImage.Freeze(); var image = new Image { Source = drawingImage, }; // Align the image with the top of the bounds of the text geometry var bounds = caretGeometry.Bounds; Canvas.SetLeft(image, bounds.Left); Canvas.SetTop(image, bounds.Top); Layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, remoteCaretSpan, null, image, null); FrameworkElement userControl = null; if (UserAvatars.ContainsKey(userIdentity.Id) && UserAvatars[userIdentity.Id].Count != 0) { userControl = UserAvatars[userIdentity.Id].Dequeue(); } if (TeamCodingPackage.Current.Settings.UserSettings.UserCodeDisplay == Options.UserSettings.UserDisplaySetting.Colour) { if (userControl == null) { userControl = new Border() { Tag = userIdentity.Id, Background = UserColours.GetUserBrush(userIdentity), CornerRadius = new CornerRadius(bounds.Height / 2 / 2) }; } userControl.Width = bounds.Height / 2; userControl.Height = bounds.Height / 2; Canvas.SetTop(userControl, bounds.Top - (userControl.Height * 0.75)); } else { if (userControl == null) { userControl = TeamCodingPackage.Current.UserImages.CreateUserIdentityControl(userIdentity); } userControl.Width = bounds.Height / 1.25f; userControl.Height = bounds.Height / 1.25f; Canvas.SetTop(userControl, bounds.Top - userControl.Height); } userControl.ToolTip = userIdentity.DisplayName ?? userIdentity.Id; Canvas.SetLeft(userControl, bounds.Left - userControl.Width / 2); Layer.AddAdornment(AdornmentPositioningBehavior.TextRelative, remoteCaretSpan, null, userControl, AdornmentRemoved); } }
/// <summary> /// Initializes a new instance of the KinectBodyView class /// </summary> /// <param name="kinectSensor">Active instance of the KinectSensor</param> public KinectBodyView(KinectSensor kinectSensor) { if (kinectSensor == null) { throw new ArgumentNullException("kinectSensor"); } // get the coordinate mapper this.coordinateMapper = kinectSensor.CoordinateMapper; // get the depth (display) extents FrameDescription frameDescription = kinectSensor.DepthFrameSource.FrameDescription; // get size of joint space this.displayWidth = frameDescription.Width; this.displayHeight = frameDescription.Height; // a bone defined as a line between two joints this.bones = new List <Tuple <JointType, JointType> >(); // Torso this.bones.Add(new Tuple <JointType, JointType>(JointType.Head, JointType.Neck)); this.bones.Add(new Tuple <JointType, JointType>(JointType.Neck, JointType.SpineShoulder)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.SpineMid)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineMid, JointType.SpineBase)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipLeft)); // Right Arm this.bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderRight, JointType.ElbowRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.ElbowRight, JointType.WristRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.HandRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.HandRight, JointType.HandTipRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.ThumbRight)); // Left Arm this.bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderLeft, JointType.ElbowLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.ElbowLeft, JointType.WristLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.HandLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.HandLeft, JointType.HandTipLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.ThumbLeft)); // Right Leg this.bones.Add(new Tuple <JointType, JointType>(JointType.HipRight, JointType.KneeRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.KneeRight, JointType.AnkleRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.AnkleRight, JointType.FootRight)); // Left Leg this.bones.Add(new Tuple <JointType, JointType>(JointType.HipLeft, JointType.KneeLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.KneeLeft, JointType.AnkleLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.AnkleLeft, JointType.FootLeft)); // populate body colors, one for each BodyIndex this.bodyColors = new List <Pen>(); this.bodyColors.Add(new Pen(Brushes.Red, 6)); this.bodyColors.Add(new Pen(Brushes.Orange, 6)); this.bodyColors.Add(new Pen(Brushes.Green, 6)); this.bodyColors.Add(new Pen(Brushes.Blue, 6)); this.bodyColors.Add(new Pen(Brushes.Indigo, 6)); this.bodyColors.Add(new Pen(Brushes.Violet, 6)); // Create the drawing group we'll use for drawing this.drawingGroup = new DrawingGroup(); // Create an image source that we can use in our image control this.imageSource = new DrawingImage(this.drawingGroup); }
/// <summary> /// Execute startup tasks /// </summary> /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> private void WindowLoaded(object sender, RoutedEventArgs e) { if (null != this.sensor) { this.sensor.SkeletonStream.TrackingMode = SkeletonTrackingMode.Default; } // Create the drawing group to use this.drawingGroup = new DrawingGroup(); // Create the image source this.imageSource = new DrawingImage(this.drawingGroup); // Display the image source Image.Source = this.imageSource; // Look through all sensors and start the first connected one. // This requires that a Kinect is connected at the time of app startup. // To make your app robust against plug/unplug, // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit (See components in Toolkit Browser). foreach (var potentialSensor in KinectSensor.KinectSensors) { if (potentialSensor.Status == KinectStatus.Connected) { this.sensor = potentialSensor; break; } } if (null != this.sensor) { // Turn on the skeleton stream to receive skeleton frames this.sensor.SkeletonStream.Enable(); // Add an event handler to be called whenever there is new color frame data this.sensor.ColorFrameReady += this.SensorColorFrameReady; // Turn on the color stream to receive color frames this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30); // Allocate space to put the pixels we'll receive this.colorPixels = new byte[this.sensor.ColorStream.FramePixelDataLength]; // This is the bitmap we'll display on-screen this.colorBitmap = new WriteableBitmap(this.sensor.ColorStream.FrameWidth, this.sensor.ColorStream.FrameHeight, 96.0, 96.0, PixelFormats.Bgr32, null); // Add an event handler to be called whenever there is new color frame data this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady; // Start the sensor! try { this.sensor.Start(); } catch (IOException) { this.sensor = null; } } if (null == this.sensor) { //this.statusBarText.Text = Properties.Resources.NoKinectReady; } alturaslider.Value = sensor.ElevationAngle; }
/// <summary> /// Initializes a new instance of the MainWindow class. /// </summary> public StudentView() { InitializeComponent(); cronometro.Start(); // one sensor is currently supported this.kinectSensor = KinectSensor.GetDefault(); // get the coordinate mapper this.coordinateMapper = this.kinectSensor.CoordinateMapper; // get the depth (display) extents FrameDescription frameDescription = this.kinectSensor.DepthFrameSource.FrameDescription; // get size of joint space this.displayWidth = frameDescription.Width; this.displayHeight = frameDescription.Height; // open the reader for the body frames this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader(); // a bone defined as a line between two joints this.bones = new List <Tuple <JointType, JointType> >(); // Torso this.bones.Add(new Tuple <JointType, JointType>(JointType.Head, JointType.Neck)); this.bones.Add(new Tuple <JointType, JointType>(JointType.Neck, JointType.SpineShoulder)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.SpineMid)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineMid, JointType.SpineBase)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipLeft)); // Right Arm this.bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderRight, JointType.ElbowRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.ElbowRight, JointType.WristRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.HandRight)); // Left Arm this.bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderLeft, JointType.ElbowLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.ElbowLeft, JointType.WristLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.HandLeft)); // Right Leg this.bones.Add(new Tuple <JointType, JointType>(JointType.HipRight, JointType.KneeRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.KneeRight, JointType.AnkleRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.AnkleRight, JointType.FootRight)); // Left Leg this.bones.Add(new Tuple <JointType, JointType>(JointType.HipLeft, JointType.KneeLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.KneeLeft, JointType.AnkleLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.AnkleLeft, JointType.FootLeft)); // populate body colors, one for each BodyIndex this.bodyColors = new List <Pen>(); this.bodyColors.Add(new Pen(Brushes.Red, 6)); this.bodyColors.Add(new Pen(Brushes.Orange, 6)); this.bodyColors.Add(new Pen(Brushes.Green, 6)); this.bodyColors.Add(new Pen(Brushes.Blue, 6)); this.bodyColors.Add(new Pen(Brushes.Indigo, 6)); this.bodyColors.Add(new Pen(Brushes.Violet, 6)); // set IsAvailableChanged event notifier this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged; // open the sensor this.kinectSensor.Open(); // Create the drawing group we'll use for drawing this.drawingGroup = new DrawingGroup(); // Create an image source that we can use in our image control this.imageSource = new DrawingImage(this.drawingGroup); // use the window object as the view model in this simple example this.DataContext = this; // initialize the components (controls) of the window StreamWriter arquivo; string arqPath = "C:\\Users\\VOXAR\\Documents\\BodyBasics-WPF\\joints.txt"; arquivo = File.CreateText(arqPath); arquivo.Close(); }
/// <summary> /// Initializes a new instance of the MainWindow class. /// </summary> public KinectDisplayWindow() { // one sensor is currently supported this.kinectSensor = KinectSensor.GetDefault(); // get the coordinate mapper this.coordinateMapper = this.kinectSensor.CoordinateMapper; // get the depth (display) extents FrameDescription frameDescription = this.kinectSensor.DepthFrameSource.FrameDescription; // get size of joint space this.displayWidth = frameDescription.Width; this.displayHeight = frameDescription.Height; // open the reader for the body frames this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader(); // a bone defined as a line between two joints this.bones = new List <Tuple <JointType, JointType> >(); // Torso this.bones.Add(new Tuple <JointType, JointType>(JointType.Head, JointType.Neck)); this.bones.Add(new Tuple <JointType, JointType>(JointType.Neck, JointType.SpineShoulder)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.SpineMid)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineMid, JointType.SpineBase)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineShoulder, JointType.ShoulderLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.SpineBase, JointType.HipLeft)); // Right Arm this.bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderRight, JointType.ElbowRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.ElbowRight, JointType.WristRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.HandRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.HandRight, JointType.HandTipRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristRight, JointType.ThumbRight)); // Left Arm this.bones.Add(new Tuple <JointType, JointType>(JointType.ShoulderLeft, JointType.ElbowLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.ElbowLeft, JointType.WristLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.HandLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.HandLeft, JointType.HandTipLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.WristLeft, JointType.ThumbLeft)); // Right Leg this.bones.Add(new Tuple <JointType, JointType>(JointType.HipRight, JointType.KneeRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.KneeRight, JointType.AnkleRight)); this.bones.Add(new Tuple <JointType, JointType>(JointType.AnkleRight, JointType.FootRight)); // Left Leg this.bones.Add(new Tuple <JointType, JointType>(JointType.HipLeft, JointType.KneeLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.KneeLeft, JointType.AnkleLeft)); this.bones.Add(new Tuple <JointType, JointType>(JointType.AnkleLeft, JointType.FootLeft)); // populate body colors, one for each BodyIndex this.bodyColors = new List <Pen>(); this.bodyColors.Add(new Pen(Brushes.Red, 6)); this.bodyColors.Add(new Pen(Brushes.Orange, 6)); this.bodyColors.Add(new Pen(Brushes.Green, 6)); this.bodyColors.Add(new Pen(Brushes.Blue, 6)); this.bodyColors.Add(new Pen(Brushes.Indigo, 6)); this.bodyColors.Add(new Pen(Brushes.Violet, 6)); // set IsAvailableChanged event notifier this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged; // open the sensor this.kinectSensor.Open(); // set the status text this.StatusText = this.kinectSensor.IsAvailable ? Properties.Resources.RunningStatusText : Properties.Resources.NoSensorStatusText; // Create the drawing group we'll use for drawing this.drawingGroup = new DrawingGroup(); // Create an image source that we can use in our image control this.imageSource = new DrawingImage(this.drawingGroup); // use the window object as the view model in this simple example this.DataContext = this; // initialize the components (controls) of the window this.InitializeComponent(); }
private void Window_Loaded(object sender, RoutedEventArgs e) { this.radioButton1.IsChecked = false; this.fileNameTextBox.Text = @"C:\Output\test"; this.drawingGroup = new DrawingGroup(); this.imageSource = new DrawingImage(this.drawingGroup); this.skeletonImage.Source = this.imageSource; if (KinectSensor.KinectSensors.Count > 0) { this._sensor = KinectSensor.KinectSensors[0]; if (this._sensor.Status == KinectStatus.Connected) { this._sensor.ColorStream.Enable(); this._sensor.DepthStream.Enable(); this._sensor.SkeletonStream.Enable(); this._sensor.AllFramesReady += new EventHandler<AllFramesReadyEventArgs>(this._sensor_AllFramesReady); this._skeletonData = new Skeleton[this._sensor.SkeletonStream.FrameSkeletonArrayLength]; this._sensor.SkeletonFrameReady += new EventHandler<SkeletonFrameReadyEventArgs>(this._sensor_SkeletonFrameReady); this._sensor.Start(); } } }