void Update()
        {
            // If world center is target then tracking pose should be set to main camera's transform
            if (worldCenterMode == WorldCenterMode.TARGET)
            {
                TrackingState  trackingState  = TrackerManager.GetInstance().GetTrackingState();
                TrackingResult trackingResult = trackingState.GetTrackingResult();
                if (trackingResult.GetCount() > 0)
                {
                    Trackable trackable  = trackingResult.GetTrackable(0);
                    Matrix4x4 targetPose = trackable.GetTargetPose().inverse;

                    if (targetPose == Matrix4x4.zero)
                    {
                        return;
                    }

                    Quaternion rotation = Quaternion.Euler(90, 0, 0);
                    Matrix4x4  m        = Matrix4x4.TRS(new Vector3(0, 0, 0), rotation, new Vector3(1, 1, 1));
                    targetPose = m * targetPose;

                    Camera.main.transform.position   = MatrixUtils.PositionFromMatrix(targetPose);
                    Camera.main.transform.rotation   = MatrixUtils.QuaternionFromMatrix(targetPose);
                    Camera.main.transform.localScale = MatrixUtils.ScaleFromMatrix(targetPose);
                }
            }
        }
        private void Update()
        {
            if (this.meshFilter != null)
            {
                meshFilter.mesh.Clear();
            }

            GuideInfo guideInfo = TrackerManager.GetInstance().GetGuideInfo();

            int featureCount = guideInfo.GetFeatureCount();

            if (featureCount == 0)
            {
                return;
            }

            float[] featureBuffer = guideInfo.GetFeatureBuffer();

            if (featureBuffer.Length > 0)
            {
                Vector3[] vertexVector3Array = convertFloatToVertex3(featureBuffer, featureCount);

                Generate(vertexVector3Array);
            }
        }
 /// <summary>
 /// Get TrackerManager instance
 /// </summary>
 /// <returns></returns>
 public static TrackerManager GetInstance()
 {
     if (instance == null)
     {
         instance = new TrackerManager();
     }
     return(instance);
 }
 private void Start()
 {
     if (applyAll)
     {
         TrackerManager.GetInstance().AddTrackerData("All : " + markerGroupSize);
     }
     else
     {
         TrackerManager.GetInstance().AddTrackerData("All : " + defaultSize);
     }
 }
 private void Start()
 {
     if (applyAll)
     {
         TrackerManager.GetInstance().AddTrackerData("{\"marker\":\"scale\",\"all\":" + markerGroupSize + "}");
     }
     else
     {
         TrackerManager.GetInstance().AddTrackerData("{\"marker\":\"scale\",\"all\":" + defaultSize + "}");
     }
 }
示例#6
0
        public void FindImageOfCloudRecognition()
        {
            if (autoState)
            {
                return;
            }

            new Thread(() => {
                TrackingState trackingState   = TrackerManager.GetInstance().GetTrackingState();
                TrackingResult trackingResult = trackingState.GetTrackingResult();
                TrackedImage trackedImage     = trackingState.GetImage();

                int trackingCount = trackingResult.GetCount();
                if (trackingCount == 0)
                {
                    if (cloudState == CloudState.CLOUDSTATE_TRACKING || cloudState == CloudState.CLOUDSTATE_STOP)
                    {
                        cloudState = CloudState.CLOUDSTATE_FEATURE_COLLECT_READY;
                    }
                }
                else
                {
                    cloudState = CloudState.CLOUDSTATE_TRACKING;
                }

                if (cloudState != CloudState.CLOUDSTATE_FEATURE_COLLECT_READY)
                {
                    return;
                }


                GetCloudRecognition(trackedImage, (bool cloudResult, string featureBase64) =>
                {
                    if (cloudResult)
                    {
                        this.featureBase64 = featureBase64;
                        this.cloudState    = CloudState.CLOUDSTATE_CONNECT;
                    }
                    else
                    {
                        this.cloudState = CloudState.CLOUDSTATE_FEATURE_COLLECT_READY;
                    }

                    if (this.restart)
                    {
                        this.loopState = true;
                        this.restart   = false;
                    }
                });
            }).Start();
        }
示例#7
0
        private void GetCloudRecognition(TrackedImage trackedImage, System.Action <bool, string> complete)
        {
            if (secretId == null || secretKey == null)
            {
                complete(false, null);
                Debug.LogError("invalid SecretId, SecretKey");
            }
            else
            {
                if (secretId.Length < 10 || secretKey.Length < 10)
                {
                    complete(false, null);
                    Debug.LogError("invalid SecretId, SecretKey");
                    return;
                }
                int[] resultLength      = { 0, 0 };
                bool  recognitionResult = false;
                if (TrackerManager.GetInstance().IsTrackerDataLoadCompleted() || cloudState == CloudState.CLOUDSTATE_FEATURE_COLLECT_READY)
                {
                    isGetFeatureState = true;
                    recognitionResult = GetFeatureClient(trackedImage, this.cloudFeatureData, resultLength);
                    isGetFeatureState = false;
                }

                if (isDestroy)
                {
                    DestroySingleTon();
                }

                if (this.restart == true)
                {
                    complete(false, null);
                }
                else
                {
                    if (recognitionResult && resultLength[0] > 0)
                    {
                        string sendString = Convert.ToBase64String(this.cloudFeatureData, 0, resultLength[0]);
                        complete(true, sendString);
                    }
                    else
                    {
                        complete(false, null);
                    }
                }
            }
        }
        internal void LOAD()
        {
            List <KeyValuePair <string, string> > removeList = new List <KeyValuePair <string, string> >();
            List <KeyValuePair <string, string> > addList    = new List <KeyValuePair <string, string> >();

            foreach (KeyValuePair <string, string> each in cloudList)
            {
                CloudRecognitionLocalData cloudRecognitionLocalData = JsonReader.Deserialize <CloudRecognitionLocalData>(each.Value);
                if (cloudRecognitionLocalData.cloud_image_path != "")
                {
                    string map_path = "";
                    if (cloudRecognitionLocalData.cloud_image_path != "")
                    {
                        map_path = Path.GetDirectoryName(cloudRecognitionLocalData.cloud_image_path) + "/" + Path.GetFileNameWithoutExtension(cloudRecognitionLocalData.cloud_image_path) + ".2dmap";
                    }
                    else if (cloudRecognitionLocalData.cloud_2dmap_path != "")
                    {
                        map_path = cloudRecognitionLocalData.cloud_2dmap_path;
                    }
                    if (File.Exists(map_path))
                    {
                        removeList.Add(each);
                        string command = "{\"cloud\":\"add_image\",\"cloud_2dmap_path\":\"" + map_path + "\",\"image_width\":" + cloudRecognitionLocalData.image_width + ",\"cloud_name\":\"" + cloudRecognitionLocalData.cloud_name + "\",\"cloud_meta\":\"" + cloudRecognitionLocalData.cloud_meta + "\"}";
                        addList.Add(new KeyValuePair <string, string>(each.Key, command));
                    }
                }
            }

            foreach (KeyValuePair <string, string> each in removeList)
            {
                cloudList.Remove(each);
            }

            foreach (KeyValuePair <string, string> each in addList)
            {
                cloudList.Add(each);
            }

            TrackerManager.GetInstance().RemoveTrackerData("");
            foreach (KeyValuePair <string, string> each in cloudList)
            {
                TrackerManager.GetInstance().AddTrackerData(each.Value);
            }
            TrackerManager.GetInstance().LoadTrackerData();
        }
示例#9
0
        internal void StartCloud()
        {
            loopState       = true;
            this.cloudState = CloudState.CLOUDSTATE_FEATURE_COLLECT_READY;
            while (this.loopState)
            {
                Thread.Sleep(100);

                TrackingState  trackingState  = TrackerManager.GetInstance().UpdateTrackingState();
                TrackingResult trackingResult = trackingState.GetTrackingResult();
                TrackedImage   trackedImage   = trackingState.GetImage();

                int trackingCount = trackingResult.GetCount();
                if (trackingCount == 0)
                {
                    if (cloudState == CloudState.CLOUDSTATE_TRACKING)
                    {
                        cloudState = CloudState.CLOUDSTATE_FEATURE_COLLECT_READY;
                    }
                }
                else
                {
                    cloudState = CloudState.CLOUDSTATE_TRACKING;
                }

                if (trackingCount == 0 && (cloudState == CloudState.CLOUDSTATE_TRACKING || cloudState == CloudState.CLOUDSTATE_FEATURE_COLLECT_READY))
                {
                    if (!TrackerManager.GetInstance().IsTrackerDataLoadCompleted() || cloudState == CloudState.CLOUDSTATE_STOP)
                    {
                        continue;
                    }

                    isGetFeatureState = true;
                    bool isCameraMove = CameraDevice.GetInstance().CheckCameraMove(trackedImage);
                    isGetFeatureState = false;
                    if (isCameraMove)
                    {
                        GetCloudRecognition(trackedImage, (bool cloudResult, string featureBase64) =>
                        {
                            if (cloudResult)
                            {
                                this.featureBase64 = featureBase64;
                                this.cloudState    = CloudState.CLOUDSTATE_CONNECT;
                            }
                            else
                            {
                                this.cloudState = CloudState.CLOUDSTATE_FEATURE_COLLECT_READY;
                            }

                            if (this.restart)
                            {
                                this.loopState = true;
                                this.restart   = false;
                            }
                            cloudSemaphore.Release();
                        });
                        cloudSemaphore.WaitOne();
                    }
                }

                if (this.cloudState == CloudState.CLOUDSTATE_STOP)
                {
                    this.loopState = false;
                }
            }
        }
示例#10
0
        private void Update()
        {
            if (cloudState == CloudState.CLOUDSTATE_CONNECT)
            {
                cloudState = CloudState.CLOUDSTATE_CONNECTING;

                CloudRecognitionAPIController.Instance.Recognize(this.secretId, this.secretKey, featureBase64, (recognitionResult) =>
                {
                    if (this.restart == true && recognitionResult == null)
                    {
                        this.cloudState = CloudState.CLOUDSTATE_FEATURE_COLLECT_READY;

                        return;
                    }

                    CloudRecognitionData cloudRecognitionData = null;
                    try
                    {
                        cloudRecognitionData = JsonReader.Deserialize <CloudRecognitionData>(recognitionResult);
                    }
                    catch (Exception ex)
                    {
                        Debug.Log("error");
                        this.cloudState = CloudState.CLOUDSTATE_FEATURE_COLLECT_READY;
                        return;
                    }

                    if (recognitionResult != null && cloudRecognitionData.ImgId != "" && cloudRecognitionData.ImgGSUrl != "")
                    {
                        Debug.Log(recognitionResult);
                        string fileName = Path.GetFileName(cloudRecognitionData.ImgGSUrl);
                        CloudRecognitionAPIController.Instance.DownloadCloudDataAndSave(cloudRecognitionData.ImgGSUrl, fileName, (localPath) =>
                        {
                            if (this.restart == true)
                            {
                                this.cloudState = CloudState.CLOUDSTATE_FEATURE_COLLECT_READY;
                                return;
                            }

                            if (localPath == null)
                            {
                                this.cloudState = CloudState.CLOUDSTATE_FEATURE_COLLECT_READY;
                                return;
                            }

                            TrackingState trackingState   = TrackerManager.GetInstance().GetTrackingState();
                            TrackingResult trackingResult = trackingState.GetTrackingResult();
                            if (trackingResult.GetCount() > 0)
                            {
                                cloudState = CloudState.CLOUDSTATE_TRACKING;
                            }
                            else
                            {
                                string mapDirectory  = Path.GetDirectoryName(localPath);
                                string mapFilePath   = mapDirectory + "/" + Path.GetFileNameWithoutExtension(localPath) + ".2dmap";
                                string imageFilePath = localPath;

                                string customToBase64 = "";
                                if (cloudRecognitionData.Custom != null)
                                {
                                    byte[] customToByteArray = Encoding.UTF8.GetBytes(cloudRecognitionData.Custom);
                                    customToBase64           = Convert.ToBase64String(customToByteArray);
                                }

                                string command = "";
                                if (File.Exists(mapFilePath))
                                {
                                    command = "{\"cloud\":\"add_image\",\"cloud_2dmap_path\":\"" + mapFilePath + "\",\"image_width\":" + cloudRecognitionData.RealWidth + ",\"cloud_name\":\"" + cloudRecognitionData.Name + "\",\"cloud_meta\":\"" + customToBase64 + "\"}";
                                }
                                else
                                {
                                    command = "{\"cloud\":\"add_image\",\"cloud_image_path\":\"" + imageFilePath + "\",\"output_path\":\"" + mapFilePath + "\",\"image_width\":" + cloudRecognitionData.RealWidth + ",\"cloud_name\":\"" + cloudRecognitionData.Name + "\",\"cloud_meta\":\"" + customToBase64 + "\"}";
                                }

                                if (this.restart == true || command == "")
                                {
                                    this.cloudState = CloudState.CLOUDSTATE_FEATURE_COLLECT_READY;
                                    return;
                                }

                                TrackerManager.GetInstance().StartTracker(TrackerManager.TRACKER_TYPE_IMAGE);
                                CloudRecognizerCache.GetInstance().ADD(fileName, command);
                                CloudRecognizerCache.GetInstance().LOAD();

                                cloudState = CloudState.CLOUDSTATE_TRACKING;
                            }
                        });
                    }
                    else
                    {
                        this.cloudState = CloudState.CLOUDSTATE_FEATURE_COLLECT_READY;
                    }
                });
            }
        }