Ejemplo n.º 1
0
        void saliencySecondsTimer_Tick()//(object sender, EventArgs e)
        {
            uint sumX = 0, sumY = 0;

            for (int i = 0; i < saliency.ToArray().Length; i++)
            {
                sumX += saliency[i].x;
                sumY += saliency[i].y;
            }
            avgPoint.x = (uint)(sumX / saliency.Length);
            avgPoint.y = (uint)(sumY / saliency.Length);


            //List<float> pos = new List<float>() { avgPoint.x, avgPoint.y };

            lblpoint.Invoke(new Action(() =>
            {
                lblpoint.Text = "X = " + avgPoint.x + " ; Y = " + avgPoint.y;
            }));


            sa.position = new List <float>()
            {
                avgPoint.x, avgPoint.y
            };

            if (sa != null)
            {
                sceneData = ComUtils.XmlUtils.Serialize <Saliency>(sa);
                //Console.WriteLine(sceneData);

                yarpPort.sendData(sceneData);
                sceneData = null;// se non cancello col tempo mi occupa tutta la memoria
            }
        }
Ejemplo n.º 2
0
            public void ThreadPoolCallback(Object outputYarpPort)
            {
                YarpPort outYarpPort = (YarpPort)outputYarpPort;

                byte[] serializedFrameByte  = _frame.Serialize;
                string serialiedFrameString = Convert.ToBase64String(serializedFrameByte);

                outYarpPort.sendData(serialiedFrameString);
                _doneEvent.Set();
            }
Ejemplo n.º 3
0
        private void SendData()
        {
            while (true)
            {
                if (StringYarp == null)
                {
                    continue;
                }

                yarpPortScene.sendData(StringYarp);
            }
        }
Ejemplo n.º 4
0
        private void ProcessData(Object data)
        {
            string receivedData = (string)data;

            byte[] serialiedFrame = Convert.FromBase64String(receivedData);
            frame.Deserialize(serialiedFrame);
            // frame contains at least one hand
            bool right = false;
            bool left  = false;

            handsValues.Time       = frame.Timestamp;
            handsValues.LeftValues = new float[9] {
                -1f, -1f, -1f, -1f, -1f, -1f, -1f, -1f, -1f
            };
            handsValues.RightValues = new float[9] {
                -1f, -1f, -1f, -1f, -1f, -1f, -1f, -1f, -1f
            };
            foreach (Leap.Hand hand in frame.Hands)
            {
                if (hand.IsValid)
                {
                    float[] anglesArray = new float[9];
                    for (int finger = 0; finger < ftype.Length; finger++)
                    {
                        Leap.Matrix[] basis     = new Leap.Matrix[3];
                        Leap.Vector[] positions = new Leap.Vector[4];

                        for (int bone = 0; bone < btype.Length; bone++)
                        {
                            if (bone < 3)
                            {
                                basis[bone] = hand.Fingers.FingerType(ftype[finger])[0].Bone(btype[bone]).Basis.RigidInverse();
                            }
                            positions[bone] = hand.Fingers.FingerType(ftype[finger])[0].Bone(btype[bone]).NextJoint;
                        }

                        // angleFlex sums 3 flexion angles per finger (metacarpal to proximal - proximal to intermediate - intermediate to distal)
                        float angleFlex = 0;
                        for (int joint = 0; joint < 3; joint++)
                        {
                            angleFlex -= basis[joint].TransformPoint(positions[joint + 1] - positions[joint]).Pitch;
                        }
                        angleFlex           = angleFlex * DEG_TO_RAD;
                        anglesArray[finger] = angleFlex;

                        if (ftype[finger] == Finger.FingerType.TYPE_INDEX || ftype[finger] == Finger.FingerType.TYPE_MIDDLE || ftype[finger] == Finger.FingerType.TYPE_THUMB)
                        {
                            float angleAbd = basis[0].TransformPoint(positions[1] - positions[0]).Yaw *DEG_TO_RAD;
                            anglesArray[finger + 5] = angleAbd;
                        }
                    }

                    anglesArray[8] = -1; // wrist angle

                    float[] vettoreAngoliNorm = normalize(anglesArray);

                    #region leftHand
                    if (hand.IsLeft && !left)
                    {
                        handsValues.LeftValues = vettoreAngoliNorm;
                        left = true;

                        for (int i = 1; i < 10; i++)
                        {
                            string labelName = String.Format("lblLH{0:D1}", i);
                            this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background,
                                                   new Action(() => ((Label)this.FindName(labelName)).Content = String.Format("{0:F2}", anglesArray[i - 1])));

                            string sliderName = String.Format("sldLH{0:D1}", i);
                            this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background,
                                                   new Action(() => ((Slider)this.FindName(sliderName)).Value = vettoreAngoliNorm[i - 1]));
                        }

                        LHSent += 1;
                        this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background,
                                               new Action(() => lblLHSent.Content = LHSent));
                    }
                    #endregion

                    #region rightHand
                    if (hand.IsRight && !right)
                    {
                        handsValues.RightValues = vettoreAngoliNorm;
                        right = true;

                        for (int i = 1; i < 10; i++)
                        {
                            string labelName = String.Format("lblRH{0:D1}", i);
                            this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background,
                                                   new Action(() => ((Label)this.FindName(labelName)).Content = String.Format("{0:F2}", anglesArray[i - 1])));

                            string sliderName = String.Format("sldRH{0:D1}", i);
                            this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background,
                                                   new Action(() => ((Slider)this.FindName(sliderName)).Value = vettoreAngoliNorm[i - 1]));
                        }

                        RHSent += 1;
                        this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background,
                                               new Action(() => lblRHSent.Content = RHSent));
                    }
                    #endregion

                    #region send to yarp
                    string toSend = ComUtils.XmlUtils.Serialize <LRValues>(handsValues) + " ";
                    yarpPortSend.sendData(toSend);
                    #endregion
                }
            }
        }
Ejemplo n.º 5
0
        // The engineLoop thread executes RunEngine() function. This thread waits until a signal is received
        // (frameReady.WaitOne()). In this case, the signal means that the copy of frame bytes is ready.
        // Since the engineLoop thread is not the UI thread (the thread which manages the interface),
        // it cannot modify objects belonging to the interface. A Dispatcher object (the last line of the function)
        // is necessary for updating the interface.
        void RunEngine(object state)
        {
            // Acquire frame for specific reference



            //if (kinect.camera.frameReady.WaitOne())
            //{
            lock (lockThis)
            {
                ColorFrame frame = colorRef.AcquireFrame();

                // It's possible that we skipped a frame or it is already gone
                if (frame == null)
                {
                    return;
                }

                uint size = Convert.ToUInt32(frame.FrameDescription.Height * frame.FrameDescription.Width * 4);
                frame.CopyConvertedFrameDataToIntPtr(kinect.Camera.PinnedImageBuffer, size, ColorImageFormat.Bgra);

                frame.Dispose();

                content = engine.Process(kinect.Camera.PinnedImageBuffer + 1, 1920, 1080, 1U, 4, 1920 * 4, 0, "GRAYSCALE");

                if (content == null)
                {
                    return;
                }

                ShoreList.Clear();

                for (uint i = 0; i < content.GetObjectCount(); i++)
                {
                    try
                    {
                        ShoreNetObject sObj = content.GetObject(i);
                        if (sObj.GetShoreType() == "Face")
                        {
                            Shore shore = new Shore();

                            shore.Eyes.Left.X  = sObj.GetMarkerOf("LeftEye").GetX();
                            shore.Eyes.Left.Y  = sObj.GetMarkerOf("LeftEye").GetY();
                            shore.Eyes.Right.X = sObj.GetMarkerOf("RightEye").GetX();
                            shore.Eyes.Right.Y = sObj.GetMarkerOf("RightEye").GetY();

                            shore.Gender          = (sObj.GetAttributeOf("Gender") == "Female") ? "Female" : "Male";
                            shore.Age             = (int)sObj.GetRatingOf("Age");
                            shore.Happiness_ratio = sObj.GetRatingOf("Happy");
                            shore.Surprise_ratio  = sObj.GetRatingOf("Surprised");
                            shore.Anger_ratio     = sObj.GetRatingOf("Angry");
                            shore.Sadness_ratio   = sObj.GetRatingOf("Sad");
                            shore.Uptime          = sObj.GetRatingOf("Uptime");
                            shore.Age_deviation   = sObj.GetRatingOf("AgeDeviation");


                            shore.Region_face.Left   = sObj.GetRegion().GetLeft();
                            shore.Region_face.Top    = sObj.GetRegion().GetTop();
                            shore.Region_face.Bottom = sObj.GetRegion().GetBottom();
                            shore.Region_face.Right  = sObj.GetRegion().GetRight();



                            ShoreList.Add(shore);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("error shore" + e.Message);
                    }
                }


                lblFaceDet.Invoke(new Action(() =>
                {
                    lblFaceDet.Text = ShoreList.Count().ToString();
                }));
            }

            if (ShoreList.Count() != 0)
            {
                ShoreData = ComUtils.XmlUtils.Serialize <List <Shore> >(ShoreList);
                //Console.WriteLine(sceneData);

                yarpPort.sendData(ShoreData);
                ShoreData = null;    // se non cancello col tempo mi occupa tutta la memoria
            }


            //}
        }
Ejemplo n.º 6
0
        RecognizedQRCode getInformationDB(Dictionary <string, ZXing.ResultPoint[]> dict)
        {
            RecognizedQRCode rec = new RecognizedQRCode();

            rec.ResolutionCam        = new ResolutionCam();
            rec.ResolutionCam.Width  = w.ToString();
            rec.ResolutionCam.Height = h.ToString();


            foreach (var s in dict)
            {
                //preparo l'informazione del soggetto con la posizione centrale del QRCode
                InfoQRCode inf = new InfoQRCode();
                inf.Positions = new List <Pos>();

                foreach (var v in s.Value)
                {
                    Pos p = new Pos();
                    p.X = v.X.ToString();
                    p.Y = v.Y.ToString();

                    inf.Positions.Add(p);
                }

                // verifico se già conosco il soggetto altrimenti interogo il database
                List <InfoQRCode> sub = SubjRecognition.InfoQRCode.FindAll(a => a.Message.Split('|')[1].Trim() == s.Key);
                if (sub.Count() == 0)
                {
                    //leggo lo status del database se è occupato attendo
                    string state = "";

                    do
                    {
                        yarpPortStatusDB.receivedData(out state);
                    }while (state != "Activo");

                    //apro le connessioni con il db
                    yarpPortCommandDB.openConnectionToDb(dataBaseCommand_OUT, dataBaseCommand_IN);
                    yarpPortReplyDB.openReceiverReplyDb(dataBaseReply_OUT, dataBaseReply_IN);

                    yarpPortCommandDB.sendData("SELECT * FROM subjects WHERE IdSubject=" + s.Key);
                    System.Threading.Thread.Sleep(400);

                    //attendo risposta
                    string reply = "";
                    do
                    {
                        yarpPortReplyDB.receivedData(out reply);
                    }while (reply == "");

                    //se non trovo nulla parte evento che gestire l'inserimento del nuovo soggetto
                    if (reply.Replace("\"", "") == "|")
                    {
                        InputDialog.InputDialog dialog2 = new InputDialog.InputDialog("Assign ID and Name to ", "", "");
                        if (dialog2.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            if (dialog2.ResultText != "unknown")
                            {
                                yarpPortCommandDB.sendData("INSERT INTO subjects (IdSubject,Name,FirstTime) VALUE ('" + s.Key + "','" + dialog2.ResultText + "','" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "')");

                                System.Threading.Thread.Sleep(400);

                                reply = "";
                                do
                                {
                                    yarpPortReplyDB.receivedData(out reply);
                                }while (reply == "" || reply == "\"|\"");

                                inf.Message = "unknown";
                            }
                            else
                            {
                                inf.Message = dialog2.ResultText;
                            }
                        }
                        else
                        {
                            inf.Message = dialog2.ResultText;
                        }
                    }
                    else
                    {
                        inf.Message = reply.Replace("\"", "");
                    }



                    yarpPortCommandDB.Close();
                    yarpPortReplyDB.Close();

                    if (inf.Message != "unknown")
                    {
                        SubjRecognition.InfoQRCode.Add(inf);
                    }
                }
                else
                {
                    foreach (InfoQRCode info in sub)
                    {
                        if (info.Message[1] == s.Key[0])
                        {
                            inf.Message = info.Message;
                        }
                    }
                }

                Sub.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                                           new Action(delegate()
                {
                    Sub.Content = inf.Message;
                }));


                rec.InfoQRCode.Add(inf);
            }


            return(rec);
        }