コード例 #1
0
 public ShoreNetObject(ShoreNetContent shContent, UInt32 i)
     : this(shContent, ShoreCContentGetObject(shContent.ptr, i))
 {
     if (ptr == IntPtr.Zero)
     {
         throw new NullReferenceException();
     }
 }
コード例 #2
0
 private ShoreNetObject(ShoreNetContent parent, IntPtr ptr)
 {
     this.parent = parent;
     this.ptr    = ptr;
 }
コード例 #3
0
ファイル: ShoreNet.cs プロジェクト: FACE-Team/SceneAnalyzer
 private ShoreNetObject(ShoreNetContent parent, IntPtr ptr)
 {
     this.parent = parent;
     this.ptr = ptr;
 }
コード例 #4
0
ファイル: ShoreNet.cs プロジェクト: FACE-Team/SceneAnalyzer
 public ShoreNetObject(ShoreNetContent shContent, UInt32 i)
     : this(shContent, ShoreCContentGetObject(shContent.ptr, i))
 {
     if (ptr == IntPtr.Zero)
         throw new NullReferenceException();
 }
コード例 #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.
        private void RunEngine()
        {
            while (kinect.frameReady.WaitOne())
            {
                content = engine.Process(imageIntPr + 1, fWidth, fHeight, 1U, kinect.pixelFeed, lineFeed, 0, "GRAYSCALE");

                if (content == null) return;

                Canvas_Shore.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                new Action(delegate()
                {
                    Canvas_Shore.Children.Clear();
                }));


                List<Subject> sh = new List<Subject>() { };

                for (uint i = 0; i < content.GetObjectCount(); i++)
                {
                    try
                    {
                        ShoreNetObject sObj = content.GetObject(i);
                        if (sObj.GetShoreType() == "Face")
                        {
                            bool present = false;
                            System.Windows.Point middleEyes = new System.Windows.Point((sObj.GetMarkerOf("LeftEye").GetX() + sObj.GetMarkerOf("RightEye").GetX()) / 2, sObj.GetMarkerOf("LeftEye").GetY());

                            sceneSubjectsCopy = sceneSubjects.ToList();

                            for (int j = 0; j < sceneSubjectsCopy.Count; j++)
                            {
                                if (sceneSubjectsCopy[j].normalizedspincenter_xy != null)
                                {
                                    //calcolo lo spine
                                    double zeta = sceneSubjectsCopy[j].spincenter_xyz[2];

                                    System.Windows.Point spinInCanvas = new System.Windows.Point();
                                    if (sceneSubjectsCopy[j].trackedState)
                                        spinInCanvas = new System.Windows.Point((int)(sceneSubjectsCopy[j].normalizedspincenter_xy[0] * kinect.sensor.DepthStream.FrameWidth),
                                            (int)(kinect.sensor.DepthStream.FrameHeight - (sceneSubjectsCopy[j].normalizedspincenter_xy[1] * kinect.sensor.DepthStream.FrameHeight)));
                                    else
                                        spinInCanvas = new System.Windows.Point((int)(sceneSubjectsCopy[j].normalizedspincenter_xy[0] * kinect.sensor.ColorStream.FrameWidth),
                                            (int)(kinect.sensor.ColorStream.FrameHeight - (sceneSubjectsCopy[j].normalizedspincenter_xy[1] * kinect.sensor.ColorStream.FrameHeight)));




                                    double ErrorX = spinInCanvas.X - middleEyes.X; 

                                    if (Math.Abs(ErrorX) < DeltaErrorX)
                                    {
                                        try
                                        {
                                            sceneSubjects[j].gender = (sObj.GetAttributeOf("Gender") == "Female") ?  "Female" :"Male";
                                            sceneSubjects[j].age = (int)sObj.GetRatingOf("Age"); 
                                            sceneSubjects[j].happiness_ratio = sObj.GetRatingOf("Happy"); 
                                            sceneSubjects[j].surprise_ratio = sObj.GetRatingOf("Surprised"); 
                                            sceneSubjects[j].anger_ratio = sObj.GetRatingOf("Angry"); 
                                            sceneSubjects[j].sadness_ratio =sObj.GetRatingOf("Sad");  
                                            sceneSubjects[j].uptime = sObj.GetRatingOf("Uptime");
                                            sceneSubjects[j].middleeyes_xy = new List<float>() { (float)middleEyes.X, (float)middleEyes.Y };

                                            present = true;
                                        }
                                        catch (Exception e)
                                        {
                                            Console.WriteLine("Shore Error" + e.Message);
                                        }
                                        
                                        break;
                                    }
                                }
                            }

                            if (!present)
                            {
                            
                                Subject newSub = new Subject();
                                newSub.idKinect = 0;
                                newSub.angle = 0;
                                newSub.gender = (sObj.GetAttributeOf("Gender") == "Female") ? "Female" : "Male";
                                newSub.age = (int)sObj.GetRatingOf("Age");
                                newSub.happiness_ratio = sObj.GetRatingOf("Happy");
                                newSub.surprise_ratio = sObj.GetRatingOf("Surprised");
                                newSub.anger_ratio = sObj.GetRatingOf("Angry");
                                newSub.sadness_ratio = sObj.GetRatingOf("Sad");
                                newSub.uptime = sObj.GetRatingOf("Uptime");
                                newSub.middleeyes_xy = new List<float>() { (float)middleEyes.X, (float)middleEyes.Y };

                                newSub.normalizedspincenter_xy = new List<float>() { };
                                newSub.spincenter_xyz = new List<float>() { };
                                newSub.lefthand_xyz = new List<float>(){ };
                                newSub.righthand_xyz = new List<float>() { };
                                newSub.head_xyz = new List<float>() { };
                                newSub.leftwrist_xyz = new List<float>(){ };
                                newSub.rightwrist_xyz = new List<float>() { };
                                newSub.leftelbow_xyz = new List<float>() { };
                                newSub.rightelbow_xyz = new List<float>() { };
                                newSub.leftshoulder_xyz = new List<float>() { };
                                newSub.rightshoulder_xyz = new List<float>() { };

                                sh.Add(newSub);


                            }

                            #region draw in canvas

                            Dictionary<string, float> expRatio = new Dictionary<string, float>() 
                            {
                                { "Angry", sObj.GetRatingOf("Angry") },
                                { "Happy", sObj.GetRatingOf("Happy") },
                                { "Sad", sObj.GetRatingOf("Sad") },
                                { "Surprised", sObj.GetRatingOf("Surprised") }
                            };
                            float ratioVal = (float)Math.Round((decimal)expRatio.Values.Max(), 1);
                            string ratioName = expRatio.OrderByDescending(kvp => kvp.Value).First().Key;

                            // Draw subject information: Gender, age +/- deviation, expression, expression rate
                            StringBuilder sb = new StringBuilder();
                            sb.AppendLine(sObj.GetAttributeOf("Gender"));
                            sb.AppendLine("Age: " + sObj.GetRatingOf("Age") + " +/- " + sObj.GetRatingOf("AgeDeviation"));
                            sb.AppendLine(ratioName + ": " + ratioVal + "%");
                            
                          
                           

                           
                            double width = Math.Abs(sObj.GetRegion().GetLeft() - sObj.GetRegion().GetRight());
                            double height = Math.Abs(sObj.GetRegion().GetTop() - sObj.GetRegion().GetBottom());
                            double left = sObj.GetRegion().GetLeft();
                            double top = sObj.GetRegion().GetTop();
                            double bottom =  sObj.GetRegion().GetBottom();
                            string gender = sObj.GetAttributeOf("Gender");

                            Canvas_Shore.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
                            new Action(delegate()
                            {
                                Rectangle rect = new Rectangle();
                                rect.Width = width;
                                rect.Height = height;
                                rect.StrokeThickness = 2;
                                rect.Stroke = (gender == "Female") ? Brushes.Fuchsia : Brushes.Cyan;
                                rect.Margin = new Thickness(left, top, 0, 0); //draw the rectangle

                                Label lab = new Label
                                {
                                    Foreground = (gender == "Female") ? Brushes.Fuchsia : Brushes.Cyan,
                                    FontSize = 12,
                                    FontWeight = FontWeights.Bold,
                                    Content = sb.ToString(),
                                    Opacity = 1,
                                    Margin = new Thickness(left,bottom, 0, 0) //draw under the rectangle
                                };


                                    Canvas_Shore.Children.Add(rect);
                                    Canvas_Shore.Children.Add(lab);

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

                    }
                }

                sceneSubjectsShore = sh;
               
            }
        }