// This function sends both how many skeletons are in the frame, and where they are private void sendOSCSkeletonPositions(object sender, SkeletonFrameReadyEventArgs e) { sendOSCSkeletonCount(); List <Skeleton> skeletonList = kinectGroup.getMasterSkeletons(); OscBundle oscBundle = new OscBundle(); int skeletonNum = 0; float xScale = sanitizeTextToFloat(XScaleTextBox.Text); float xOffset = sanitizeTextToFloat(XOffsetTextBox.Text); float yScale = sanitizeTextToFloat(YScaleTextBox.Text); float yOffset = sanitizeTextToFloat(YOffsetTextBox.Text); foreach (Skeleton s in skeletonList) { var oscMessage = new OscElement("/skeletonPosition", skeletonNum, (float)(s.Position.X * SCREEN_WIDTH_PX_M_RATIO * xScale + xOffset), (float)(s.Position.Y * SCREEN_HEIGHT_PX_M_RATIO * yScale + yOffset), (float)(s.Position.Z * SCREEN_WIDTH_PX_M_RATIO * xScale + xOffset), (int)(s.TrackingId)); oscBundle.AddElement(oscMessage); skeletonNum++; } oscWriter.Send(oscBundle); }
void sendToOsc(string line, String channel, UdpWriter oscWriter) { String[] splitted = line.Split(' '); OscBundle b = new OscBundle(0); int i = 0; //Remove the Label i++; b.AddElement(new OscElement("/" + channel + "/timestamp", splitted[i++])); // splitted.Length - 1 because the linebreak creates one more blank string when splitting for (i = 2; i < splitted.Length - 1; i += 3) { b.AddElement(new OscElement("/kinect" + ((i + 1) / 3).ToString(), splitted[i], splitted[i + 1], splitted[i + 2]) ); } oscWriter.Send(b); }
private void startUp() { hook = new UserActivityHook(); hook.KeyDown += (s, keycode, isCtrl) => { OscElement msg = new OscElement(textOSC.Text, textId.Text, keycode.ToString()); OscBundle bundle = new OscBundle(); bundle.AddElement(msg); oscmanager.Send(bundle); textIndata.Text = keycode.ToString(); }; }
private void SendHandLocation(Skeleton skeleton) { Joint right = skeleton.Joints[JointType.HandRight]; Joint left = skeleton.Joints[JointType.HandLeft]; OscBundle msg = new OscBundle(0, new OscElement("/right/x", right.Position.X), new OscElement("/right/y", right.Position.Y), new OscElement("/right/z", right.Position.Z), new OscElement("/left/x", left.Position.X), new OscElement("/left/y", left.Position.Y), new OscElement("/left/z", left.Position.Z)); if (this.euclidDist(right.Position, left.Position) < 10 && right.Position.Y > 0.3) { msg.AddElement(new OscElement("/gestures/swell", 1.0f)); } //OscBundle msg = new OscBundle(0, new OscElement("/gestures/swell", 1.0f)); udpwriter.Send(msg); uw2.Send(msg); }
public void sendOsc(string channel, FaceTrackFrame faceFrame, UdpWriter oscWriter) { TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1); String time = ((long)t.TotalMilliseconds).ToString(); var shape = faceFrame.Get3DShape(); float[][] arr = shape .Select(x => new float[3] { x.X, x.Y, x.Z }) .ToArray(); OscBundle b = new OscBundle(0); int i = 0; foreach (var v in shape) { var el = new OscElement("/kinect" + i++, v.X, v.Y, v.Z); b.AddElement(el); } oscWriter.Send(b); }
//Methods public void sendOscMessage(OscElement messageElement) { bundle.AddElement(messageElement); writer.Send(bundle); }
// This function sends both how many skeletons are in the frame, and where they are private void sendOSCSkeletonPositions(object sender, SkeletonFrameReadyEventArgs e) { sendOSCSkeletonCount(); List<Skeleton> skeletonList = kinectGroup.getMasterSkeletons(); OscBundle oscBundle = new OscBundle(); int skeletonNum = 0; float xScale = sanitizeTextToFloat(XScaleTextBox.Text); float xOffset = sanitizeTextToFloat(XOffsetTextBox.Text); float yScale = sanitizeTextToFloat(YScaleTextBox.Text); float yOffset = sanitizeTextToFloat(YOffsetTextBox.Text); foreach (Skeleton s in skeletonList){ var oscMessage = new OscElement("/skeletonPosition", skeletonNum, (float)(s.Position.X * SCREEN_WIDTH_PX_M_RATIO * xScale + xOffset), (float)(s.Position.Y * SCREEN_HEIGHT_PX_M_RATIO * yScale + yOffset), (float)(s.Position.Z * SCREEN_WIDTH_PX_M_RATIO * xScale + xOffset), (int)(s.TrackingId)); oscBundle.AddElement(oscMessage); skeletonNum++; } oscWriter.Send(oscBundle); }
/// <summary> /// Handles the body frame data arriving from the sensor /// </summary> /// <param name="sender">object sending the event</param> /// <param name="e">event arguments</param> private void Reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e) { bool dataReceived = false; using (BodyFrame bodyFrame = e.FrameReference.AcquireFrame()) { if (bodyFrame != null) { if (this.bodies == null) { this.bodies = new Body[bodyFrame.BodyCount]; } // The first time GetAndRefreshBodyData is called, Kinect will allocate each Body in the array. // As long as those body objects are not disposed and not set to null in the array, // those body objects will be re-used. bodyFrame.GetAndRefreshBodyData(this.bodies); dataReceived = true; } } if (dataReceived) { using (DrawingContext dc = this.drawingGroup.Open()) { // Draw a transparent background to set the render size dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, this.displayWidth, this.displayHeight)); int penIndex = 0; int bodyIndex = 0; OscBundle oscBundle = new OscBundle(DateTime.Now); foreach (Body body in this.bodies) { Pen drawPen = this.bodyColors[penIndex++]; if (body.IsTracked) { bodyIndex++; this.DrawClippedEdges(body, dc); IReadOnlyDictionary <JointType, Joint> joints = body.Joints; // convert the joint points to depth (display) space Dictionary <JointType, Point> jointPoints = new Dictionary <JointType, Point>(); foreach (JointType jointType in joints.Keys) { // sometimes the depth(Z) of an inferred joint may show as negative // clamp down to 0.1f to prevent coordinatemapper from returning (-Infinity, -Infinity) CameraSpacePoint position = joints[jointType].Position; if (position.Z < 0) { position.Z = InferredZPositionClamp; } // add all joints data to osc bundle Object[] args = new Object[10]; args[0] = bodyIndex; args[1] = (int)jointType; args[2] = position.X; args[3] = position.Y; args[4] = position.Z; args[5] = body.JointOrientations[jointType].Orientation.X; args[6] = body.JointOrientations[jointType].Orientation.Y; args[7] = body.JointOrientations[jointType].Orientation.Z; args[8] = body.JointOrientations[jointType].Orientation.W; args[9] = (int)joints[jointType].TrackingState; // JointType: https://msdn.microsoft.com/en-us/library/microsoft.kinect.jointtype.aspx foreach (OscConnection oscConnection in oscConnectionList) { if (oscConnection.OscUdpWriter != null) { string oscAddress = "/" + kinectSensor.UniqueKinectId; if (oscConnection.Identifier != null) { if (oscConnection.Identifier != "") { oscAddress = "/" + oscConnection.Identifier; } } OscElement oscElement = new OscElement(oscAddress, args); oscConnection.OscUdpWriter.Send(oscElement); oscBundle.AddElement(oscElement); } } DepthSpacePoint depthSpacePoint = this.coordinateMapper.MapCameraPointToDepthSpace(position); jointPoints[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y); } this.DrawBody(joints, jointPoints, dc, drawPen); this.DrawHand(body.HandLeftState, jointPoints[JointType.HandLeft], dc); this.DrawHand(body.HandRightState, jointPoints[JointType.HandRight], dc); } } // send osc bundle // if (oscUdpWriter != null) // oscUdpWriter.SendBundle(oscBundle); // prevent drawing outside of our render area this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, this.displayWidth, this.displayHeight)); } } }
/// <summary> /// Sends a skeleton's position and depth via OSC /// </summary> /// <param name="skeleton">skeleton to send</param> private void SendSkeletonOsc(Skeleton skeleton) { OscBundle b = new OscBundle(); b.AddElement(GetOscJointMessage(skeleton, JointType.AnkleLeft)); b.AddElement(GetOscJointMessage(skeleton, JointType.AnkleRight)); b.AddElement(GetOscJointMessage(skeleton, JointType.ElbowLeft)); b.AddElement(GetOscJointMessage(skeleton, JointType.ElbowRight)); b.AddElement(GetOscJointMessage(skeleton, JointType.FootLeft)); b.AddElement(GetOscJointMessage(skeleton, JointType.FootRight)); b.AddElement(GetOscJointMessage(skeleton, JointType.HandLeft)); b.AddElement(GetOscJointMessage(skeleton, JointType.HandRight)); b.AddElement(GetOscJointMessage(skeleton, JointType.Head)); b.AddElement(GetOscJointMessage(skeleton, JointType.HipCenter)); b.AddElement(GetOscJointMessage(skeleton, JointType.HipLeft)); b.AddElement(GetOscJointMessage(skeleton, JointType.HipRight)); b.AddElement(GetOscJointMessage(skeleton, JointType.KneeLeft)); b.AddElement(GetOscJointMessage(skeleton, JointType.KneeRight)); b.AddElement(GetOscJointMessage(skeleton, JointType.ShoulderCenter)); b.AddElement(GetOscJointMessage(skeleton, JointType.ShoulderLeft)); b.AddElement(GetOscJointMessage(skeleton, JointType.ShoulderRight)); b.AddElement(GetOscJointMessage(skeleton, JointType.Spine)); b.AddElement(GetOscJointMessage(skeleton, JointType.WristLeft)); b.AddElement(GetOscJointMessage(skeleton, JointType.WristRight)); OSCsend.Send(b); }
public static void ShapeStatus(int shape1, int shape2) { //Console.WriteLine("Got Shape Status"); OscBundle bundle = new OscBundle(); bundle.AddElement(new OscElement("/shape1/" + shape1)); bundle.AddElement(new OscElement("/shape2/" + shape2)); //send bundle OSCSender.Send(bundle); }
static void Main(string[] args) {//UDP writer for OSC UdpWriter udpWrite = new UdpWriter("127.0.0.1", 7000); try { Nuitrack.Init(""); } catch (Exception exception) { Console.WriteLine("Cannot initialize Nuitrack."); throw exception; } try { // Create and setup all required modules _depthSensor = DepthSensor.Create(); _userTracker = UserTracker.Create(); _skeletonTracker = SkeletonTracker.Create(); } catch (Exception exception) { Console.WriteLine("Cannot create Nuitrack module."); Console.WriteLine(exception.Message); throw exception; } // Add event handlers for all modules _depthSensor.OnUpdateEvent += OnDepthSensorUpdate; _userTracker.OnNewUserEvent += OnUserTrackerNewUser; _userTracker.OnLostUserEvent += OnUserTrackerLostUser; _skeletonTracker.OnSkeletonUpdateEvent += OnSkeletonUpdate; // Add an event handler for the IssueUpdate event Nuitrack.onIssueUpdateEvent += OnIssueDataUpdate; try { Nuitrack.Run(); Console.WriteLine(DateTime.Now.ToString()); } catch (Exception exception) { Console.WriteLine("Cannot start Nuitrack."); throw exception; } bool a = true; while (a) { int start = (int)DateTime.Now.TimeOfDay.TotalMilliseconds; // Update Nuitrack data. Data will be synchronized with skeleton time stamps. try { Nuitrack.Update(_skeletonTracker); } catch (LicenseNotAcquiredException exception) { Console.WriteLine(DateTime.Now.ToString()); Console.WriteLine("LicenseNotAcquired exception. Exception: {0}", exception); throw exception; } catch (Exception exception) { Console.WriteLine("Nuitrack update failed. Exception: ", exception); } if (_skeletonData != null) { //Create new bundle for each time skeleton data is refreshed OscBundle bundle = new OscBundle(); //const int jointSize = 10; foreach (var skeleton in _skeletonData.Skeletons) { foreach (var joint in skeleton.Joints) { float[] rotationMatrix = joint.Orient.Matrix; //Ignore joints that are not currently used by Nuitrack if (joint.Type == JointType.None || joint.Type == JointType.LeftFingertip || joint.Type == JointType.RightFingertip || joint.Type == JointType.LeftFoot || joint.Type == JointType.RightFoot) { continue; } //Create new message element for joint containing joint type and rotation matrix OscElement jointMessage = new OscElement("/" + joint.Type, joint.Real.X, joint.Real.Y, joint.Real.Z, rotationMatrix[0], rotationMatrix[1], -1 * rotationMatrix[2], rotationMatrix[3], rotationMatrix[4], -1 * rotationMatrix[5], -1 * rotationMatrix[6], -1 * rotationMatrix[7], rotationMatrix[8]); Console.WriteLine(joint.Real.X + " " + joint.Real.Y + " " + joint.Real.Z); bundle.AddElement(jointMessage); } //Send the message bundle with the data udpWrite.Send(bundle); int difference = delay - start - (int)DateTime.Now.TimeOfDay.TotalMilliseconds; System.Threading.Thread.Sleep(delay); } } } Nuitrack.Release(); Console.ReadLine(); }
public static void Timeout() { OscBundle bundle = new OscBundle(); bundle.AddElement(new OscElement("/timeout")); //send bundle OSCSender.Send(bundle); logger.AddLogWithTime("Timeout"); }
public static void HoldingFail(int player) { OscBundle bundle = new OscBundle(); bundle.AddElement(new OscElement("/holdfail" + player)); //send bundle OSCSender.Send(bundle); }
public static void RoundStart(int goalShape, int orientation, IntPtr goalShapeStatus) { //Console.WriteLine("Sending Round Start"); OscBundle bundle = new OscBundle(); bundle.AddElement(new OscElement("/roundstart")); //send bundle OSCSender.Send(bundle); int[] goalShapes = new int[4*6]; Marshal.Copy(goalShapeStatus, goalShapes, 0, 4*6); logger.AddLogWithTime("RoundStart " + numPhotos + " " + goalShape + " " + orientation, goalShapes); }
public static void GameStart() //not used. { OscBundle bundle = new OscBundle(); bundle.AddElement(new OscElement("/gamestart")); //send bundle OSCSender.Send(bundle); }
public static void ShapeCompleted(int winner, int scoreP1, int scoreP2) { OscBundle bundle = new OscBundle(); bundle.AddElement(new OscElement("/pwins", winner)); //send bundle OSCSender.Send(bundle); logger.AddLogWithTime("Win " + winner + " " + scoreP1 + " " + scoreP2); }
private void KinectSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { var skeletons = new Skeleton[0]; using (var skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skeletons); } } if (skeletons.Length == 0) { return; } var skel = skeletons.FirstOrDefault(x => x.TrackingState == SkeletonTrackingState.Tracked); if (skel == null) { return; } var rightHand = skel.Joints[JointType.WristRight]; XValueRight.Text = rightHand.Position.X.ToString(CultureInfo.InvariantCulture); YValueRight.Text = rightHand.Position.Y.ToString(CultureInfo.InvariantCulture); ZValueRight.Text = rightHand.Position.Z.ToString(CultureInfo.InvariantCulture); var leftHand = skel.Joints[JointType.WristLeft]; XValueLeft.Text = leftHand.Position.X.ToString(CultureInfo.InvariantCulture); YValueLeft.Text = leftHand.Position.Y.ToString(CultureInfo.InvariantCulture); ZValueLeft.Text = leftHand.Position.Z.ToString(CultureInfo.InvariantCulture); var centreHip = skel.Joints[JointType.HipCenter]; /* * Below this is where the code edit was made. * ******************* */ //creates the var manager = new OscManager(); //Sets up the IP address and Port to which the bundle is sending to. //Edit DestIP to the laptop your communicating with. manager.DestIP = "192.168.0.26"; manager.DestPort = 12000; //Creates the message and bundle. This is what will send the data. OscElement message; OscBundle bundle; if (leftHand.Position.Y > .2) { //Lower octave message = new OscElement("/octave", 0); bundle = new OscBundle(); bundle.AddElement(message); manager.Send(bundle); } else if ((leftHand.Position.Y > .2) && (leftHand.Position.Y < .45)) { //Mid octave message = new OscElement("/octave", 1); bundle = new OscBundle(); bundle.AddElement(message); manager.Send(bundle); } else if (leftHand.Position.Y > .50) { //High octave message = new OscElement("/octave", 2); bundle = new OscBundle(); bundle.AddElement(message); manager.Send(bundle); } /******** * This ends where the code was edited */ if (rightHand.Position.Y > 0.3) { RightRaised.Text = "Raised"; } else if (leftHand.Position.Y > 0.3) { LeftRaised.Text = "Raised"; } else { LeftRaised.Text = "Lowered"; RightRaised.Text = "Lowered"; } //Pauses system so not too many signals are being sent. Thread.Sleep(10); }