public static void Run(string[] args)
        {
            var xefPath = @"C:\XEF\cam2_cal.xef";
            var xef     = new Xef(xefPath);
            //Load computer vision (CV) color file
            var colorCV = xef.LoadCvColorFrame(0);

            colorCV.DrawAruco().ShowNoWait();
            var cameraSpace = xef.LoadCVCameraSpace(2);

            var(tx, markers) = Calibrator.Calibrate(colorCV, cameraSpace);
            var pose = tx
                       .CameraSpaceToWorldTx
                       .ToMat();

            var camSpaceTx = cameraSpace.Transform(pose)
                             .ToCamSpacePoints();

            //Save as XYZRGB file (open in MeshLab to view)
            XYZRGB.Export(camSpaceTx, colorCV.GetBRGABytes(), @"C:\XEF\cam2_cal.txt");
            markers = markers.OrderByDescending(m => m.MaskSum.Val0).Take(4).ToList();
            var markerPoints = new CvCameraSpace();

            markers.ForEach(m => markerPoints.Add(m.KxCenter));
            var txMarkers = markerPoints.Transform(pose);

            XYZRGB.Export(txMarkers, new Scalar(255, 0, 0), @"C:\XEF\cam2_cal_markers.txt");
        }
예제 #2
0
 public Boolean LoadCalibration()
 {
     try
     {
         CalibrationData data = CalibrationPersister.LoadCalibrationData();
         if (calibrator == null)
         {
             calibrator = new Calibrator(screenWidth, screenHeight);
         }
         calibrator.Calibrate(data);
         isCalibrated = true;
         return(true);
     }
     catch (CalibrationDataNotFoundException)
     {
         return(false);
     }
 }
        private async void ReCalibrate()
        {
            String title       = NSBundle.MainBundle.LocalizedString("Vernacular_P0_dialog_calibration_title", null).PrepareForLabel();
            String calibrating = NSBundle.MainBundle.LocalizedString("Vernacular_P0_dialog_calibration_description", null).PrepareForLabel();

            // Show progress
            BTProgressHUD.Show(title + " " + calibrating);

            var result = await _calibrator.Calibrate();

            CalibrationTerminated(result);
        }
예제 #4
0
        public async Task <CalibrationResult> Calibrate(Activity parentActivity)
        {
            if (IsCalibrating)
            {
                throw new InvalidOperationException("Calibration operation already started");
            }
            IsCalibrating = true;

            var dialog = new ProgressDialog(parentActivity);

            dialog.SetTitle(Resource.String.Vernacular_P0_dialog_calibration_title);
            dialog.SetMessage(parentActivity.GetString(Resource.String.Vernacular_P0_dialog_calibration_description));
            dialog.SetCancelable(false);
            dialog.SetIcon(Resource.Drawable.icon_accelerometer);
            dialog.SetProgressStyle(ProgressDialogStyle.Spinner);
            dialog.Indeterminate = true;
            dialog.Show();

            dialog.Window.AddFlags(WindowManagerFlags.KeepScreenOn);

            var result = await _calibrator.Calibrate();

            // Early termination if parent activity is not around anymore
            if (parentActivity.IsDestroyed || parentActivity.IsFinishing)
            {
                return(CalibrationResult.Canceled);
            }
            dialog.Dismiss();

            if (result != CalibrationResult.Completed)
            {
                _failedAttempts++;

                Toast.MakeText(parentActivity, GetStringId(result), ToastLength.Long).Show();

                if (_failedAttempts >= 3)
                {
                    var errorDialog = new AlertDialog.Builder(parentActivity)
                                      .SetTitle(Resource.String.Vernacular_P0_error_generic_reflective)
                                      .SetMessage(Resource.String.Vernacular_P0_error_calibration_several_attempts)
                                      .SetCancelable(true)
                                      .SetPositiveButton(Resource.String.Vernacular_P0_dialog_ok, (IDialogInterfaceOnClickListener)null)
                                      .SetIcon(Resource.Drawable.icon_accelerometer)
                                      .Create();
                    errorDialog.Show();
                }
            }

            IsCalibrating = false;

            return(result);
        }
    IEnumerator CalibrateRoutine()
    {
        if (!Directory.Exists(directory))
        {
            yield break;
        }
        ;

        var files = Directory.GetFiles(directory);

        files = files.Where(e => targetExtensions.Contains(Path.GetExtension(e).ToLower())).ToArray();
        if (files.Length < 1)
        {
            yield break;
        }
        ;

        calibrator.Setup();
        for (var i = 0; i < files.Length; i++)
        {
            using (Mat gray = Imgcodecs.imread(files[i], Imgcodecs.IMREAD_GRAYSCALE))
            {
                if (i == 0)
                {
                    Init(gray);
                }
                calibrator.Calibrate(gray);
                if (draw)
                {
                    Imgproc.cvtColor(gray, rgbMat, Imgproc.COLOR_GRAY2RGB);
                    calibrator.Draw(gray, rgbMat);
                    Utils.matToTexture2D(rgbMat, texture);
                    renderer.material.mainTexture = texture;
                }

                print("progress : " + (i + 1) + " / " + files.Length);
                yield return(new WaitForSeconds(interval));
            }
        }
        if (autoSave)
        {
            calibrator.Save(IOHandler.IntoStreamingAssets(fileName));
        }

        calibrator.Clear();

        print("Complete Calibration");
        yield break;
    }
예제 #6
0
        public static void Run()
        {
            var xefPath = @"C:\XEF\cam1_cal.xef";
            var xef     = new Xef(xefPath);
            //Load computer vision (CV) color file
            var colorCV     = xef.LoadCvColorFrame(0);
            var cameraSpace = xef.LoadCVCameraSpace(0);
            var pose        = Calibrator.Calibrate(colorCV, cameraSpace)
                              .Transform
                              .CameraSpaceToWorldTx
                              .ToMat();

            cameraSpace.Transform(pose);
            //Save as XYZRGB file (open in MeshLab to view)
            XYZRGB.Export(cameraSpace.ToCamSpacePoints(), colorCV.GetBRGABytes(), @"C:\XEF\cam1_cal.txt");
        }
예제 #7
0
        private void NewImage(object sender, NewImageEventArgs e)
        {
            //if (PenPositionChanged != null) PenPositionChanged(this, PenTracker.GetPenPosition(e.NewImage));
            _gridcheck--;
            if (_gridcheck == 0) // calibration check needed
            {
                _gridcheck = 1000;
                switch (_calibrator.CheckCalibration())
                {
                case 1: Calibrator.Calibrate();
                    break;

                case 2: Calibrator.CalibrateColors();
                    break;
                }
            }
        }
예제 #8
0
        public IEnumerator Calibrate()
        {
            var settings = new RootMotion.FinalIK.VRIKCalibrator.Settings();

            //トラッカー
            //xをプラス方向に動かすとトラッカーの左(LEDを上に見たとき)に進む
            //yをプラス方向に動かすとトラッカーの上(LED方向)に進む
            //zをマイナス方向に動かすとトラッカーの底面に向かって進む

            //角度補正(左手なら右のトラッカーに向けた)後
            //xを+方向は体の正面に向かって進む
            //yを+方向は体の上(天井方向)に向かって進む
            //zを+方向は体中心(左手なら右手の方向)に向かって進む
            var leftHandOffset = new Vector3(1.0f, leftHandTrackerOffsetToBottom, leftHandTrackerOffsetToBodySide);  // Vector3 (IsEnable, ToTrackerBottom, ToBodySide)
            //}
            //if (CurrentSettings.RightHand.Item1 == ETrackedDeviceClass.GenericTracker) {
            //角度補正(左手なら右のトラッカーに向けた)後
            //xを-方向は体の正面に向かって進む
            //yを+方向は体の上(天井方向)に向かって進む
            //zを+方向は体中心(左手なら右手の方向)に向かって進む
            var rightHandOffset = new Vector3(1.0f, rightHandTrackerOffsetToBottom, rightHandTrackerOffsetToBodySide);  // Vector3 (IsEnable, ToTrackerBottom, ToBodySide)

            //}
            //if (calibrateType == PipeCommands.CalibrateType.Default) {

            if (calibrationType == CalibrationType.VirtualMotionCaptureScaled)
            {
                yield return(Calibrator.CalibrateScaled(_refs.RealTrackerRoot, _refs.HandTrackerRoot, _refs.HeadTrackerRoot, _refs.PelvisTrackerRoot,
                                                        dummyVrik, settings, leftHandOffset, rightHandOffset, pelvisTrackerAdjustmentToBottom,
                                                        _data.headTracker, _data.bodyTracker, _data.leftHandTracker, _data.rightHandTracker, _data.leftFootTracker, _data.rightFootTracker, _data.leftElbowTracker, _data.rightElbowTracker, _data.leftKneeTracker, _data.rightKneeTracker));
            }
            else
            {
                yield return(Calibrator.Calibrate(_refs.RealTrackerRoot, _refs.HandTrackerRoot, _refs.HeadTrackerRoot, _refs.PelvisTrackerRoot,
                                                  dummyVrik, settings, leftHandOffset, rightHandOffset, pelvisTrackerAdjustmentToBottom,
                                                  _data.headTracker, _data.bodyTracker, _data.leftHandTracker, _data.rightHandTracker, _data.leftFootTracker, _data.rightFootTracker, _data.leftElbowTracker, _data.rightElbowTracker, _data.leftKneeTracker, _data.rightKneeTracker));
            }

            dummyVrik.solver.IKPositionWeight = 1.0f;
            if (_refs.handler.Trackers.Count == 1)
            {
                dummyVrik.solver.plantFeet         = true;
                dummyVrik.solver.locomotion.weight = 1.0f;
                var rootController = dummyVrik.references.root.GetComponent <RootMotion.FinalIK.VRIKRootController> ();
                if (rootController != null)
                {
                    GameObject.Destroy(rootController);
                }
            }

            dummyVrik.solver.locomotion.footDistance   = 0.06f;
            dummyVrik.solver.locomotion.stepThreshold  = 0.2f;
            dummyVrik.solver.locomotion.angleThreshold = 45f;
            dummyVrik.solver.locomotion.maxVelocity    = 0.04f;
            dummyVrik.solver.locomotion.velocityFactor = 0.04f;
            dummyVrik.solver.locomotion.rootSpeed      = 40;
            dummyVrik.solver.locomotion.stepSpeed      = 2;

            //トラッカー位置の非表示
            _refs.RealTrackerRoot.gameObject.SetActive(false);

            _UpdateHandRotation();
        }