Beispiel #1
0
 private void FreeInternData()
 {
     video.Close();
     if (nb_frame > parameters.starting_frame)
     {
         if (parameters.use_detection == true)
         {
             CARDSVideoPlugin.FreeCopyFrameWrapped(ref frame_buffer_background);
         }
         unsafe
         {
             fixed(Target *out_targets = targets)
             {
                 Debug.Log("Free targets");
                 CARDSTrackingPlugin.CloseWrapped(out_targets, ref nb_targets, max_targets);
             }
         }
     }
 }
    private void SetEstimateWorldPosition(Target t)
    {
        if (t.state != StateTracker.Undefined)
        {
            Matrix4x4f mat = CARDSTrackingPlugin.EstimatePoseWrapped(ref t, ref parameters.calibration);
            //float depth = mat.c_23 * parameters.calibration.dist_cam;

            //TODO Debug purpose
            float depth = parameters.calibration.dist_cam;

            Vector2 screenpoint = GetCenterScreenTarget(t);
            Vector3 worldPoint  = GetScreenToWorldSpace(screenpoint, depth);

            /* REAL POSE TODO
             * Vector3 worldPoint = new Vector3(mat.c_03, mat.c_23, mat.c_13);
             */
            //Debug.Log(worldPoint);
            if (!estimate_pos.ContainsKey(t.id))
            {
                estimate_pos[t.id] = Vector3.zero;
            }
            estimate_pos[t.id] = Vector3.Slerp(estimate_pos[t.id], worldPoint, 0.4f);
        }
    }
Beispiel #3
0
    /// <summary>
    /// Start point.
    /// </summary>
    protected void OnEnable()
    {
        DebugTargets[] debugs = gameObject.GetComponents <DebugTargets>();
        if (debugs.Length > 0)
        {
            Debug.LogError("Debug create dynamically, component will be removed.");
            foreach (DebugTargets debug in debugs)
            {
                DestroyImmediate(debug);
            }
        }

        Debug.Log("Start tracking.");

        //File calibration
        if (parameters.use_file_calibration)
        {
            string path = Path.Combine(Application.streamingAssetsPath, parameters.path_subfolder_calibration);
            if (!Directory.Exists(path))
            {
                throw new System.Exception("Folder " + path + " does not exist.");
            }
            if (!CARDSCalibrationPlugin.GetPoseParametersWrapped(path, ref parameters.calibration))
            {
                throw new System.Exception("Loading parameters " + path + " failed.");
            }
        }
        else if (parameters.device_index != -1)
        {
            Debug.LogWarning("Not recommended to not use calibrtation file in other context than virtual.");
        }

        // Init video
        if (parameters.UseWebcam)
        {
            video = new WebcamTexture();
            gameObject.AddComponent <DebugTargetsWebcam>();
        }
        else if (parameters.device_index == -1)
        {
            video = new VirtualCameraTexture();
            gameObject.AddComponent <DebugTargetsVirtual>();
        }
        else if (parameters.device_index == -2)
        {
            video = new VideoFileTexture();
            gameObject.AddComponent <DebugTargetsVideo>();
        }
        video.Init(parameters);

        // Init plugin
        unsafe
        {
            fixed(Target *outTargets = targets)
            {
                CARDSTrackingPlugin.InitWrapped(outTargets, ref nb_targets, max_targets);
            }
        }

        //Init detection
        if (parameters.use_detection)
        {
            zone_detection = ConvertUnityScreenToRect(parameters.rect_detection);
        }

        nb_frame = -1;
    }
Beispiel #4
0
    /// <summary>
    /// Implementation in one thread.
    /// </summary>
    protected override void InternalTrackingLoop()
    {
        if (!video.GetFrame(out frame_buffer))
        {
            Debug.LogWarning("Empty frames.");
            return;
        }

        //Bakground
        if (parameters.use_detection && nb_frame == parameters.saving_background)
        {
            Debug.Log("Register background");
            CARDSVideoPlugin.GetCopyFrameWrapped(ref frame_buffer, ref frame_buffer_background);
        }

        if (nb_frame == parameters.starting_frame)
        {
            unsafe
            {
                fixed(Target *out_targets = targets)
                {
                    //Debug.Log("Register manual");
                    Time.timeScale = 0;
                    CARDSUtilitiesPlugin.ManualRegisterWrapped(ref frame_buffer, out_targets, ref nb_targets, max_targets);
                    Time.timeScale = 1;
                }
            }
        }
        else if (nb_frame > parameters.starting_frame)
        {
            //DETECTION
            if (parameters.use_detection)
            {
                if (((nb_frame % parameters.detection_frequency) == 0) && (frame_buffer_background.raw_data != null))
                {
                    unsafe
                    {
                        fixed(Target *out_targets = targets)
                        {
                            have_detected = CARDSTrackingPlugin.DetectWrapped(ref frame_buffer, ref frame_buffer_background, ref zone_detection, out_targets, ref nb_targets, max_targets, have_detected ? 1 : 0);
                            if (have_detected)
                            {
                                Debug.Log("New detect");
                            }
                        }
                    }
                }
            }
            //CHECK TRACK
            if ((nb_frame % parameters.checktrack_frequency) == 0)
            {
                unsafe
                {
                    fixed(Target *out_targets = targets)
                    {
                        //Debug.Log("CheckTrack");
                        CARDSTrackingPlugin.CheckTrackWrapped(ref frame_buffer, out_targets, max_targets);
                        if (parameters.debug_cv)
                        {
                            CARDSUtilitiesPlugin.DebugTargetsWrapped(ref frame_buffer, out_targets, max_targets);
                        }
                    }
                }
            }
            else             // TRACK
            {
                unsafe
                {
                    fixed(Target *out_targets = targets)
                    {
                        //Debug.Log("Track");
                        CARDSTrackingPlugin.TrackWrapped(ref frame_buffer, out_targets, max_targets);
                        if (parameters.debug_cv)
                        {
                            CARDSUtilitiesPlugin.DebugTargetsWrapped(ref frame_buffer, out_targets, max_targets);
                        }
                    }
                }
            }
        }
        nb_frame++;
    }