void Start() { StartCoroutine(HttpLongPollNotification("http://vcm-12481.vm.duke.edu/push/")); MLImageTracker.Start(); MLImageTracker.Enable(); MLImageTracker.AddTarget("sea", imageTarget, 0.279f, (target, result) => { if (!_imageObjectAdded && result.Status == MLImageTargetTrackingStatus.Tracked) { Debug.Log("Image recognized."); DisplayAssets(); _imageObjectAdded = true; } }, true); MLResult camera = MLCamera.Start(); if (camera.IsOk) { MLCamera.Connect(); Debug.Log("Camera Enabled"); } // MLCamera.OnRawImageAvailable += delegate(byte[] jpegBytes) { StartCoroutine(Upload(jpegBytes)); }; // StartCoroutine(Capture()); }
#pragma warning restore 649 /// <summary> /// Starts up MLImageTracker. /// Invokes the callback after privleges have been succesfully requested and MLImageTracker is started. /// </summary> public static MLResult Start() { #if PLATFORM_LUMIN _result = MLPrivilegesStarterKit.Start(); if (!_result.IsOk) { Debug.LogErrorFormat("Error: MLImageTrackerStarterKit failed when calling MLPrivilegesStarterKit.Start. Reason: {0}", _result); return(_result); } _result = MLPrivilegesStarterKit.RequestPrivileges(MLPrivileges.Id.CameraCapture); if (_result.Result != MLResult.Code.PrivilegeGranted) { Debug.LogErrorFormat("Error: MLImageTrackerStarterKit failed requesting privileges. Reason: {0}", _result); return(_result); } MLPrivilegesStarterKit.Stop(); _result = MLImageTracker.Start(); if (!_result.IsOk) { Debug.LogErrorFormat("Error: MLImageTrackerStarterKit failed starting MLImageTracker. Reason: {0}", _result); } #endif return(_result); }
/// <summary> // Adds an image target to be tracked. /// </summary> public static MLImageTargetStarterKit AddTarget(string id, Texture2D texture, float longerDimension, MLImageTracker.Target.OnImageResultDelegate callback, bool isStationary = false) { if (MLImageTracker.IsStarted) { MLImageTargetStarterKit newTargetStarterKit = new MLImageTargetStarterKit(); callback += newTargetStarterKit.HandleStatusUpdates; MLImageTracker.Target newTarget = MLImageTracker.AddTarget(id, texture, longerDimension, callback, isStationary); if (newTarget == null) { Debug.LogErrorFormat("MLImageTrackerStarterKit.AddTarget was unable to create the new image target with id: {0}.", id); return(null); } newTargetStarterKit.InitializeWithTarget(newTarget); return(newTargetStarterKit); } else { Debug.LogError("Error: MLImageTrackerStarterKit.AddTarget failed because MLImageTracker was not started."); return(null); } }
private void StartTracking() { if (MLImageTracker.IsStarted) { MLImageTracker.Enable(); anchorPlacer.SetActive(true); } }
/// <summary> // Remove an image target from being tracked. /// </summary> public static bool RemoveTarget(string id) { #if PLATFORM_LUMIN return(MLImageTracker.RemoveTarget(id)); #else return(false); #endif }
/// <summary> /// Used for enabling the image tracker without resetting the API. /// </summary> public static MLResult Enable() { #if PLATFORM_LUMIN _result = MLImageTracker.Enable(); #endif return(_result); }
private void StopTracking() { if (MLImageTracker.IsStarted) { MLImageTracker.Disable(); anchorPlacer.SetActive(false); } }
/// <summary> /// Used for getting the current tracker status. /// </summary> public static bool GetTrackerStatus() { #if PLATFORM_LUMIN return(MLImageTracker.GetTrackerStatus()); #else return(false); #endif }
/// <summary> /// Adds a new image target to be tracked. /// </summary> private void AddTarget() { #if PLATFORM_LUMIN _imageTarget = MLImageTracker.AddTarget(gameObject.GetInstanceID().ToString(), image, longerDimensionInSceneUnits, HandleAllTargetStatuses, isStationary); if (_imageTarget == null) { Debug.LogErrorFormat("MLImageTrackerBehavior.AddTarget failed to add target {0} to the image tracker.", gameObject.name); return; } #endif }
/// <summary> /// Stops MLImageTracker. /// </summary> public static void Stop() { #if PLATFORM_LUMIN if (MLImageTracker.IsStarted) { MLImageTracker.Stop(); } else { Debug.LogError("Error: MLImageTrackerStarterKit.Stop failed because MLImageTracker was not started."); } #endif }
/// <summary> /// Handles the event for trigger down. /// </summary> /// <param name="controllerId">The id of the controller.</param> /// <param name="triggerValue">The value of the trigger.</param> private void HandleOnTriggerDown(byte controllerId, float triggerValue) { if (_hasStarted && MLImageTracker.IsStarted && _controllerConnectionHandler.IsControllerValid(controllerId)) { if (MLImageTracker.GetTrackerStatus()) { MLImageTracker.Disable(); _trackerStatusLabel.text = "Tracker Status: Disabled"; } else { MLImageTracker.Enable(); _trackerStatusLabel.text = "Tracker Status: Enabled"; } } }
/// <summary> /// Used for enabling the image tracker without resetting the API. /// </summary> public static MLResult Enable() { #if PLATFORM_LUMIN if (MLImageTracker.IsStarted) { _result = MLImageTracker.Enable(); } else { _result = MLResult.Create(MLResult.Code.UnspecifiedFailure, "MLImageTracker was not started."); } #endif return(_result); }
/// <summary> // Remove an image target from being tracked. /// </summary> public static bool RemoveTarget(string id) { #if PLATFORM_LUMIN if (MLImageTracker.IsStarted) { return(MLImageTracker.RemoveTarget(id)); } else { Debug.LogError("Error: MLImageTrackerStarterKit.RemoveTarget failed because MLImageTracker was not started."); return(false); } #else return(false); #endif }
/// <summary> /// Used for getting the current tracker status. /// </summary> public static bool GetTrackerStatus() { #if PLATFORM_LUMIN if (MLImageTracker.IsStarted) { return(MLImageTracker.GetTrackerStatus()); } else { Debug.LogError("Error: MLImageTrackerStarterKit.GetTrackerStatus failed because MLImageTracker was not started."); return(false); } #else return(false); #endif }
/// <summary> /// Callback for when tracked image is found /// </summary> /// <param name="isReliable"> Contains if image found is reliable </param> private void OnTargetFound(bool isReliable) { if (!_calibrated && isReliable) { WorldOrigin.position = transform.position; WorldOrigin.rotation = transform.rotation; _calibrated = true; if (MLImageTracker.IsStarted) { MLImageTracker.Disable(); } Debug.Log("Image target found, calibration completed."); } }
/// <summary> /// Handles the event for trigger down. /// </summary> /// <param name="controllerId">The id of the controller.</param> /// <param name="triggerValue">The value of the trigger.</param> private void HandleOnTriggerDown(byte controllerId, float triggerValue) { if (_hasStarted && MLImageTracker.IsStarted && _controllerConnectionHandler.IsControllerValid(controllerId)) { // The ImageTracker status before it is changed bool trackerStatus = MLImageTracker.GetTrackerStatus(); // Try to change the ImageTracker status MLResult result = trackerStatus ? MLImageTracker.Disable() : MLImageTracker.Enable(); if (!result.IsOk) { Debug.LogErrorFormat("Error: Failed to {0} the ImageTracker.", trackerStatus ? "disable" : "enable"); } else { _trackerStatusLabel.text = "Tracker Status: " + (trackerStatus ? "Disabled" : "Enabled"); } } }
/// <summary> /// Removes the image target from the tracking system and then stops the starter kit. /// </summary> void OnDestroy() { #if PLATFORM_LUMIN MLImageTracker.RemoveTarget(gameObject.GetInstanceID().ToString()); #endif }
private void OnDestroy() { MLImageTracker.Stop(); MLImageTracker.Disable(); }