Inheritance: MonoBehaviour
Esempio n. 1
0
    void Awake()
    {
        nite = FindObjectOfType(typeof(NiteOpenNet)) as NiteOpenNet;
        userGui = FindObjectOfType(typeof(UserGuiDeformatory)) as UserGuiDeformatory;
        handDetector = FindObjectOfType(typeof(HandDetector)) as HandDetector;
        nite.NiteInitializingEvent += HandleNiteInitializingEvent;

        state = CentralDeformatory.State.Shaping;
        NextState();
    }
Esempio n. 2
0
    public override void OneDevicePartInit(Dictionary <InputDevicePartType, SCPointEventData> eventDataDic, Transform targetTransform, MoveLogic moveLogic, RotateLogic rotateLogic, ScaleLogic scaleLogic)
    {
        base.OneDevicePartInit(eventDataDic, targetTransform, moveLogic, rotateLogic, scaleLogic);
        startRotation        = targetTransform.rotation;
        onHandPointEventData = eventDataDic.Values.ToArray()[0];

        InputDeviceHandPart inputDeviceHandPart = onHandPointEventData.inputDevicePartBase as InputDeviceHandPart;
        ModelHand           modelHand           = inputDeviceHandPart.inputDeviceHandPartUI.modelHand;

        oneHandJointFour    = modelHand.ActiveHandModel.GetJointTransform(FINGER.forefinger, JOINT.Four).transform;
        localRotationInHand = Quaternion.Inverse(oneHandJointFour.rotation) * startRotation;

        handDetector = inputDeviceHandPart.detectorBase as HandDetector;

        oneHandPose.position = onHandPointEventData.Position3D;
        oneHandPose.rotation = startRotation;
        oneHandGrabPosition  = onHandPointEventData.Position3D;

        moveLogic.Setup(oneHandPose, oneHandGrabPosition, targetTransform, targetTransform.localScale);
    }
Esempio n. 3
0
        public static void Main()
        {
            var videoCapture = new VideoCapture(CaptureDevice.Any);

            if (!videoCapture.IsOpened())
            {
                Console.WriteLine("Nie można zainicjować kamery.");
            }
            else
            {
                Console.WriteLine("Zainicjowano kamerę.");

                using (var cameraWindow = new Window("Kamera"))
                    using (var hsvWindow = new Window("HSV"))
                        using (var thresholdingWindow = new Window("Progowanie obrazu"))
                            using (var controlPanelWindow = new Window("Panel sterowania"))
                                using (var handWindow = new Window("Wykrywanie dłoni"))
                                    using (var cameraImage = new Mat())
                                        using (var thresholdingImage = new Mat())
                                            using (var hsvImage = new Mat())
                                            {
                                                var controlPanelData = new ControlPanelData
                                                {
                                                    HsvModel = new HsvModel
                                                    {
                                                        Hue = new ModelItem
                                                        {
                                                            Min = 80,
                                                            Max = 110
                                                        },
                                                        Saturation = new ModelItem
                                                        {
                                                            Min = 0,
                                                            Max = 255
                                                        },
                                                        Value = new ModelItem
                                                        {
                                                            Min = 0,
                                                            Max = 255
                                                        }
                                                    },
                                                    Blur   = 3,
                                                    Erode  = 5,
                                                    Dilate = 5
                                                };

                                                AppSettings.LoadControlPanelData(controlPanelData);
                                                Console.WriteLine("Wczytano ustawienia.");

                                                cameraWindow.Move(0, 0);
                                                hsvWindow.Move(videoCapture.FrameWidth, 0);
                                                thresholdingWindow.Move(2 * videoCapture.FrameWidth, 0);
                                                controlPanelWindow.Move(0, videoCapture.FrameHeight + 32);
                                                controlPanelWindow.Resize(videoCapture.FrameWidth, videoCapture.FrameHeight);
                                                WinApiUtils.SetWindowPosition(videoCapture.FrameWidth, videoCapture.FrameHeight + 32, videoCapture.FrameWidth + 16, videoCapture.FrameHeight + 40);
                                                handWindow.Move(2 * videoCapture.FrameWidth, videoCapture.FrameHeight + 32);

                                                CreateControlPanelWindow(controlPanelWindow, controlPanelData);

                                                while (true)
                                                {
                                                    videoCapture.Read(cameraImage);
                                                    if (cameraImage.Empty())
                                                    {
                                                        Console.WriteLine("Kamera przestała odpowiadać.");
                                                        break;
                                                    }

                                                    Cv2.CvtColor(cameraImage, hsvImage, ColorConversionCodes.BGR2HSV);
                                                    Cv2.Blur(hsvImage, hsvImage, new Size(controlPanelData.Blur, controlPanelData.Blur));
                                                    Cv2.Flip(hsvImage, hsvImage, FlipMode.Y);

                                                    ThresholdImage(hsvImage, thresholdingImage, controlPanelData);
                                                    RemoveSmallObjectsFromTheForeground(thresholdingImage, controlPanelData);

                                                    cameraWindow.ShowImage(cameraImage);
                                                    hsvWindow.ShowImage(hsvImage);
                                                    thresholdingWindow.ShowImage(thresholdingImage);

                                                    HandDetector.Run(handWindow, thresholdingImage);

                                                    switch (Cv2.WaitKey(FrameRate))
                                                    {
                                                    case SpaceKey:
                                                        ControlMode = !ControlMode;
                                                        break;

                                                    case SKey:
                                                        AppSettings.SaveControlPanelData(controlPanelData);
                                                        Console.WriteLine("Zapisano ustawienia.");
                                                        break;
                                                    }
                                                }
                                            }
            }

            Console.ReadKey();
        }