Exemplo n.º 1
0
        public TestImage(FaceEncodingData faceEncoding, Rect faceLocation, Mat img, HeadRotation horizontalHeadRotation, DateTime dateCreated, bool isReferenceImg, long userId)
        {
            if (faceLocation.Width <= 0 || faceLocation.Height <= 0)
            {
                throw new ArgumentException($"Invalid faceLocation");
            }

            if (img.Empty())
            {
                throw new ArgumentException("Empty img");
            }

            if (img.Rows <= 0 || img.Cols <= 0)
            {
                throw new ArgumentException("Invalid img size");
            }

            if (horizontalHeadRotation == HeadRotation.Unknown)
            {
                throw new ArgumentException("Unknown headRotation");
            }

            FaceEncoding           = faceEncoding ?? throw new ArgumentException("Null faceEncodingData");
            FaceLocation           = faceLocation;
            Img                    = img;
            HorizontalHeadRotation = horizontalHeadRotation;
            DateCreated            = dateCreated;
            IsReferenceImg         = isReferenceImg;
            UserId                 = userId;
        }
Exemplo n.º 2
0
    void SendHeadRotationToMotionServer()
    {
        if (Application.platform != RuntimePlatform.Android)
        {
            return;
        }

        double now = (DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds;

        if (timeLastExecution < now)
        {
            timeLastExecution = now + Config.config.sendHeadRotationInterval;

            // get camera rotation
            Vector3 currentHeadPosition = Camera.main.gameObject.transform.rotation.eulerAngles;

            if (HeadPositionHasChanged(currentHeadPosition))
            {
                lastHeadPosition = currentHeadPosition;

                string json = JsonUtility.ToJson(HeadRotation.fromVector3(currentHeadPosition));

                AndroidJavaClass plugin = new AndroidJavaClass(Config.pluginClassString);
                plugin.CallStatic("sendMessageToMotionWebSocket", json);
            }
        }
    }
Exemplo n.º 3
0
        public bool ChangeRotation(RobotVO robot, HeadRotation headRotation)
        {
            if (robot.Head.HeadInclination == HeadInclination.Down)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
 //Test ctor
 internal TestImage(Rect faceLocation, Mat img, HeadRotation horizontalHeadRotation, DateTime dateCreated, bool isReferenceImg, long userId)
 {
     FaceLocation           = faceLocation;
     Img                    = img;
     HorizontalHeadRotation = horizontalHeadRotation;
     DateCreated            = dateCreated;
     IsReferenceImg         = isReferenceImg;
     UserId                 = userId;
 }
Exemplo n.º 5
0
    private void OnApplicationPause(bool pause)
    {
        if (Application.platform == RuntimePlatform.Android && pause == true)
        {
            AndroidJavaClass plugin = new AndroidJavaClass(Config.pluginClassString);

            string json = JsonUtility.ToJson(HeadRotation.fromVector3(new Vector3(0, 0, 0)));
            plugin.CallStatic("sendMessageToMotionWebSocket", json);
        }
    }
Exemplo n.º 6
0
    public static HeadRotation fromVector3(Vector3 vector)
    {
        HeadRotation rotation = new HeadRotation();

#if RASPBERRY_PI
        rotation.vertical   = EulerToPWM(vector.x, -500);
        rotation.horizontal = EulerToPWM(vector.y);
#else
        rotation.vertical   = EulerToPWM(vector.x);
        rotation.horizontal = EulerToPWM(vector.y);
#endif

        return(rotation);
    }
Exemplo n.º 7
0
    void SendHeadRotationToMotionServerMock()
    {
        double now = (DateTime.Now - new DateTime(1970, 1, 1)).TotalMilliseconds;

        if (timeLastExecution < now)
        {
            timeLastExecution = now + Config.config.sendHeadRotationInterval;

            // get camera rotation
            Vector3 currentHeadPosition = Camera.main.gameObject.transform.rotation.eulerAngles;

            if (HeadPositionHasChanged(currentHeadPosition))
            {
                lastHeadPosition = currentHeadPosition;
                string json = JsonUtility.ToJson(HeadRotation.fromVector3(currentHeadPosition));
                Debug.Log(json);
            }
            Debug.Log("Position is the same");
        }
    }
Exemplo n.º 8
0
        public void NaoDevePermitirRotacionarCabeca()
        {
            //Arrange
            var robot = new RobotVO()
            {
                Head = new HeadVO()
                {
                    HeadInclination = HeadInclination.Down,
                    HeadRotation    = HeadRotation.InRest
                }
            };

            HeadRotation headRotation = HeadRotation.Rotate45Degrees;

            //Act
            var result = _headMovement.ChangeRotation(robot, headRotation);

            //Assert
            Assert.False(result);
        }
Exemplo n.º 9
0
 private bool IsRotationMovement(RobotVO robot, HeadRotation rotation) => robot.Head.HeadRotation != rotation;
Exemplo n.º 10
0
 public TestImageBuilder AddHeadRotation(HeadRotation headRotation)
 {
     Rotation = headRotation;
     return(this);
 }
Exemplo n.º 11
0
 void Awake()
 {
     dataController = FindObjectOfType <DataController>();
     headRotation   = FindObjectOfType <HeadRotation>();
 }
        public async Task <Task> InitFace(User user, IAsyncEnumerator <Mat> camEnumerator, CancellationToken ct)
        {
            bool interrupted = true;

            var testImages    = new List <TestImageBuilder>();
            var tasks         = new List <Task>();
            var faceEncodings = new List <Task <FaceEncodingData?> >();

            _progress = 0;
            _user     = user;
            Reset();


            while (await camEnumerator.MoveNextAsync())
            {
                var frame = camEnumerator.Current;

                Rect[]       faceRects;
                HeadRotation targetRotation;

                if (testImages.Count == 0)
                {
                    faceRects = _faceDetection.DetectFrontalFaces(frame);
                    if (faceRects.Length != 1)
                    {
                        ReportInitFaceProgress(frame, state: Services.ProfileInitProgress.FaceNotDetected);
                        continue;
                    }

                    var(hRot, vRot) = _headPositionService.GetHeadPosition(frame, faceRects.First());
                    targetRotation  = hRot;
                    if (vRot != HeadRotation.Front || hRot != HeadRotation.Front)
                    {
                        ReportInitFaceProgress(frame, face: faceRects.First(),
                                               state: Services.ProfileInitProgress.FaceNotStraight);
                        continue;
                    }
                }
                else
                {
                    faceRects = _faceDetection.DetectFrontalThenProfileFaces(frame);
                    if (faceRects.Length != 1)
                    {
                        ReportInitFaceProgress(frame, state: Services.ProfileInitProgress.ProfileFaceNotDetected);

                        continue;
                    }

                    var(hRot, vRot) = _headPositionService.GetHeadPosition(frame, faceRects.First());
                    HeadRotation hTarget  = testImages.Count == 1 ? HeadRotation.Left : HeadRotation.Right;
                    HeadRotation vInvalid = testImages.Count == 1 ? HeadRotation.Right : HeadRotation.Left;
                    targetRotation = hTarget;
                    if (hRot != hTarget || vRot == vInvalid)
                    {
                        ReportInitFaceProgress(frame, face: faceRects.First(),
                                               state: hTarget == HeadRotation.Left ? Services.ProfileInitProgress.FaceNotTurnedLeft : Services.ProfileInitProgress.FaceNotTurnedRight);
                        continue;
                    }
                }

                var faceImg       = frame.Clone();
                var testImageBldr = TestImageBuilderFactory.Create();
                testImageBldr.AddImg(faceImg)
                .AddDateCreated(DateTime.UtcNow)
                .AddFaceLocation(faceRects.First())
                .AddHeadRotation(targetRotation)
                .SetUser(user)
                .SetIsReferenceImg(true);
                testImages.Add(testImageBldr);

                faceEncodings.Add(CreateFaceEncodingTask(faceImg));

                _progress += 20.34;

                ReportInitFaceProgress(frame, faceRects.First());

                if (testImages.Count > 1)
                {
                    var face1 = testImages[^ 2].Img;