private IEnumerator CreateService() { if (string.IsNullOrEmpty(_iamApikey)) { throw new WatsonException("Plesae provide IAM ApiKey for the service."); } Credentials credentials = null; // Authenticate using iamApikey TokenOptions tokenOptions = new TokenOptions() { IamApiKey = _iamApikey }; credentials = new Credentials(tokenOptions, _serviceUrl); // Wait for tokendata while (!credentials.HasIamTokenData()) { yield return(null); } // Create credential and instantiate service _visualRecognition = new VisualRecognition(credentials); _visualRecognition.VersionDate = _versionDate; Runnable.Run(Examples()); }
private IEnumerator CreateService() { if (string.IsNullOrEmpty(_iamApikey)) { throw new WatsonException("Please provide IAM ApiKey for the service."); } Credentials credentials = null; TokenOptions tokenOptions = new TokenOptions() { IamApiKey = _iamApikey }; credentials = new Credentials(tokenOptions, _serviceUrl); //wait for token while (!credentials.HasIamTokenData()) { yield return(null); } //create credentials _visualRecognition = new VisualRecognition(credentials); _visualRecognition.VersionDate = "2019-02-26"; }
private void InstantiateVR() { TokenOptions iamTokenOptionsTangram = new TokenOptions() { IamApiKey = Secrets.APIKEY_TANGRAM }; Credentials cTangram = new Credentials(iamTokenOptionsTangram); _visualRecognitionTangram = new VisualRecognition(cTangram) { VersionDate = "2018-03-19" }; TokenOptions iamTokenOptionsWaste = new TokenOptions() { IamApiKey = Secrets.APIKEY_WASTE }; Credentials cWaste = new Credentials(iamTokenOptionsWaste); _visualRecognitionWaste = new VisualRecognition(cWaste) { VersionDate = "2018-03-19" }; }
private IEnumerator CreateService() { Credentials credentials = null; if (!string.IsNullOrEmpty(_apikey)) { // Authenticate using apikey credentials = new Credentials(_apikey, _url); } else if (!string.IsNullOrEmpty(_iamApikey)) { // Authenticate using iamApikey TokenOptions tokenOptions = new TokenOptions() { IamApiKey = _iamApikey, IamUrl = _iamUrl }; credentials = new Credentials(tokenOptions, _url); // Wait for tokendata while (!credentials.HasIamTokenData()) { yield return(null); } } // Create credential and instantiate service _visualRecognition = new VisualRecognition(credentials); _visualRecognition.VersionDate = _versionDate; Runnable.Run(Examples()); }
void OnEnable() { Application.targetFrameRate = 60; Screen.sleepTimeout = SleepTimeout.NeverSleep; #if UNITY_ANDROID QuitOnEscOrBack = true; #endif if (m_ARCamera == null) { m_ARCamera = GetComponent <Camera>(); } // Fallback to main camera if (m_ARCamera == null) { m_ARCamera = Camera.main; } if (m_ARInterface == null) { m_ARInterface = InsightARInterface.GetInterface(); } if (autoStartAR) { DoStartAR(); } Credentials credentials = new Credentials("IJBxcBtV9wbCvLLS87RZ51Lbwg5ZUIJaunIb1Fb5l-Lw", "https://gateway.watsonplatform.net/visual-recognition/api"); _visualRecognition = new VisualRecognition(credentials); }
private IEnumerator CreateService() { Debug.Log("Starting API Connection"); if (string.IsNullOrEmpty(_iamApikey)) { throw new WatsonException("Please provide IAM ApiKey for the service."); } Credentials credentials = null; TokenOptions tokenOptions = new TokenOptions() { IamApiKey = _iamApikey }; credentials = new Credentials(tokenOptions, _serviceUrl); //wait for token while (!credentials.HasIamTokenData()) { yield return(null); } //create credentials _visualRecognition = new VisualRecognition(credentials); _visualRecognition.VersionDate = "2019-03-27"; Debug.Log("Finished API Connection"); classifierIds.Add(classifierId); }
//private string picURL = "C:\\Users\\Vasanth\\Downloads\\Hassan.jpg"; // Use this for initialization void Start() { Credentials credentials = new Credentials("6b7e212e6ea3425fc358e6f795ec0f99e1b3b558", "https://gateway-a.watsonplatform.net/visual-recognition/api"); _visualRecognition = new VisualRecognition(credentials); _visualRecognition.VersionDate = "2016-05-20"; }
void Start() { LogSystem.InstallDefaultReactors(); // Create credential and instantiate service Credentials credentials = new Credentials(_apikey, _url); _visualRecognition = new VisualRecognition(credentials); _visualRecognition.VersionDate = _visualRecognitionVersionDate; Runnable.Run(Examples()); }
public void check() { string _apikey = "c5df3c97d2876236f153bc90b911298420ffbfbe"; string _url = "https://gateway-a.watsonplatform.net/visual-recognition/api"; string _visualRecognitionVersionDate = "2016-05-20"; LogSystem.InstallDefaultReactors(); Credentials credentials = new Credentials(_apikey, _url); _visualRecognition = new VisualRecognition(credentials); _visualRecognition.VersionDate = _visualRecognitionVersionDate; StartCoroutine("TakePhoto"); }
// Use this for initialization void Start() { ds = new dbManager("earldb.s3db"); ds.createTable(); emoteSnackbar.SetActive(false); //defaultBackground = background.texture; if (comp) { credentials = new Credentials("fa0d719942dea6bca4fe74a70b13ef9eff1d84c5", "https://watson-api-explorer.mybluemix.net/visual-recognition/api/v3/classify?"); _visualRecognition = new VisualRecognition(credentials); _visualRecognition.VersionDate = _visualRecognitionVersionDate; startFrontCam(); } }
public override IEnumerator RunTest() { LogSystem.InstallDefaultReactors(); VcapCredentials vcapCredentials = new VcapCredentials(); fsData data = null; string result = null; string credentialsFilepath = "../sdk-credentials/credentials.json"; // Load credentials file if it exists. If it doesn't exist, don't run the tests. if (File.Exists(credentialsFilepath)) { result = File.ReadAllText(credentialsFilepath); } else { yield break; } // Add in a parent object because Unity does not like to deserialize root level collection types. result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES"); // Convert json to fsResult fsResult r = fsJsonParser.Parse(result, out data); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Convert fsResult to VcapCredentials object obj = vcapCredentials; r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Set credentials from imported credntials Credential credential = vcapCredentials.GetCredentialByname("visual-recognition-sdk")[0].Credentials; _apikey = credential.ApiKey.ToString(); _url = credential.Url.ToString(); // Create credential and instantiate service Credentials credentials = new Credentials(_apikey, _url); _visualRecognition = new VisualRecognition(credentials); _visualRecognition.VersionDate = _visualRecognitionVersionDate; // Get all classifiers Log.Debug("TestVisualRecognition.RunTest()", "Attempting to get all classifiers"); if (!_visualRecognition.GetClassifiersBrief(OnGetClassifiers, OnFail)) { Log.Debug("TestVisualRecognition.GetClassifiers()", "Failed to get all classifiers!"); } while (!_getClassifiersTested) { yield return(null); } #if TRAIN_CLASSIFIER _isClassifierReady = false; // Train classifier Log.Debug("TestVisualRecognition.RunTest()", "Attempting to train classifier"); string positiveExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_positive_examples.zip"; string negativeExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/negative_examples.zip"; Dictionary <string, string> positiveExamples = new Dictionary <string, string>(); positiveExamples.Add("giraffe", positiveExamplesPath); if (!_visualRecognition.TrainClassifier(OnTrainClassifier, OnFail, "unity-test-classifier-ok-to-delete", positiveExamples, negativeExamplesPath)) { Log.Debug("TestVisualRecognition.TrainClassifier()", "Failed to train classifier!"); } while (!_trainClassifierTested) { yield return(null); } // Find classifier by ID Log.Debug("TestVisualRecognition.RunTest()", "Attempting to find classifier by ID"); if (!_visualRecognition.GetClassifier(OnGetClassifier, OnFail, _classifierID)) { Log.Debug("TestVisualRecognition.GetClassifier()", "Failed to get classifier!"); } while (!_getClassifierTested) { yield return(null); } //// Download Core ML Model //Log.Debug("TestVisualRecognition.RunTest()", "Attempting to get Core ML Model"); //if(!_visualRecognition.GetCoreMLModel(OnGetCoreMLModel, OnFail, _classifierID)) // Log.Debug("TestVisualRecognition.GetCoreMLModel()", "Failed to get core ml model!"); //while (!_getCoreMLModelTested) // yield return null; #endif // Classify get Log.Debug("TestVisualRecognition.RunTest()", "Attempting to get classify via URL"); if (!_visualRecognition.Classify(_imageURL, OnClassifyGet, OnFail)) { Log.Debug("TestVisualRecognition.Classify()", "Classify image failed!"); } while (!_classifyGetTested) { yield return(null); } // Classify post image Log.Debug("TestVisualRecognition.RunTest()", "Attempting to classify via image on file system"); string imagesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_to_classify.jpg"; string[] owners = { "IBM", "me" }; string[] classifierIDs = { "default", _classifierID }; if (!_visualRecognition.Classify(OnClassifyPost, OnFail, imagesPath, owners, classifierIDs, 0.5f)) { Log.Debug("TestVisualRecognition.Classify()", "Classify image failed!"); } while (!_classifyPostTested) { yield return(null); } // Detect faces get Log.Debug("TestVisualRecognition.RunTest()", "Attempting to detect faces via URL"); if (!_visualRecognition.DetectFaces(_imageURL, OnDetectFacesGet, OnFail)) { Log.Debug("TestVisualRecognition.DetectFaces()", "Detect faces failed!"); } while (!_detectFacesGetTested) { yield return(null); } // Detect faces post image Log.Debug("TestVisualRecognition.RunTest()", "Attempting to detect faces via image"); string faceExamplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/obama.jpg"; if (!_visualRecognition.DetectFaces(OnDetectFacesPost, OnFail, faceExamplePath)) { Log.Debug("TestVisualRecognition.DetectFaces()", "Detect faces failed!"); } while (!_detectFacesPostTested) { yield return(null); } #if DELETE_TRAINED_CLASSIFIER Runnable.Run(IsClassifierReady(_classifierToDelete)); while (!_isClassifierReady) { yield return(null); } // Delete classifier by ID Log.Debug("TestVisualRecognition.RunTest()", "Attempting to delete classifier"); if (!_visualRecognition.DeleteClassifier(OnDeleteClassifier, OnFail, _classifierToDelete)) { Log.Debug("TestVisualRecognition.DeleteClassifier()", "Failed to delete classifier!"); } while (!_deleteClassifierTested) { yield return(null); } #endif Log.Debug("TestVisualRecognition.RunTest()", "Visual Recogition tests complete"); yield break; }
public override IEnumerator RunTest() { LogSystem.InstallDefaultReactors(); VcapCredentials vcapCredentials = new VcapCredentials(); fsData data = null; string result = null; var vcapUrl = Environment.GetEnvironmentVariable("VCAP_URL"); var vcapUsername = Environment.GetEnvironmentVariable("VCAP_USERNAME"); var vcapPassword = Environment.GetEnvironmentVariable("VCAP_PASSWORD"); using (SimpleGet simpleGet = new SimpleGet(vcapUrl, vcapUsername, vcapPassword)) { while (!simpleGet.IsComplete) { yield return(null); } result = simpleGet.Result; } // Add in a parent object because Unity does not like to deserialize root level collection types. result = Utility.AddTopLevelObjectToJson(result, "VCAP_SERVICES"); // Convert json to fsResult fsResult r = fsJsonParser.Parse(result, out data); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Convert fsResult to VcapCredentials object obj = vcapCredentials; r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Set credentials from imported credntials Credential credential = vcapCredentials.VCAP_SERVICES["visual_recognition"]; _apikey = credential.Apikey.ToString(); _url = credential.Url.ToString(); // Create credential and instantiate service Credentials credentials = new Credentials(_apikey, _url); _visualRecognition = new VisualRecognition(credentials); _visualRecognition.VersionDate = _visualRecognitionVersionDate; // Get all classifiers Log.Debug("TestVisualRecognition.RunTest()", "Attempting to get all classifiers"); if (!_visualRecognition.GetClassifiersBrief(OnGetClassifiers, OnFail)) { Log.Debug("TestVisualRecognition.GetClassifiers()", "Failed to get all classifiers!"); } while (!_getClassifiersTested) { yield return(null); } #if TRAIN_CLASSIFIER // Train classifier Log.Debug("TestVisualRecognition.RunTest()", "Attempting to train classifier"); string positiveExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_positive_examples.zip"; string negativeExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/negative_examples.zip"; Dictionary <string, string> positiveExamples = new Dictionary <string, string>(); positiveExamples.Add("giraffe", positiveExamplesPath); if (!_visualRecognition.TrainClassifier(OnTrainClassifier, OnFail, "unity-test-classifier-example", positiveExamples, negativeExamplesPath)) { Log.Debug("TestVisualRecognition.TrainClassifier()", "Failed to train classifier!"); } while (!_trainClassifierTested) { yield return(null); } // Find classifier by ID Log.Debug("TestVisualRecognition.RunTest()", "Attempting to find classifier by ID"); if (!_visualRecognition.GetClassifier(OnGetClassifier, OnFail, _classifierID)) { Log.Debug("TestVisualRecognition.GetClassifier()", "Failed to get classifier!"); } while (!_getClassifierTested) { yield return(null); } // Download Core ML Model Log.Debug("TestVisualRecognition.RunTest()", "Attempting to get Core ML Model"); if (!_visualRecognition.GetCoreMLModel(OnGetCoreMLModel, OnFail, _classifierID)) { Log.Debug("TestVisualRecognition.GetCoreMLModel()", "Failed to get core ml model!"); } while (!_getCoreMLModelTested) { yield return(null); } #endif // Classify get Log.Debug("TestVisualRecognition.RunTest()", "Attempting to get classify via URL"); if (!_visualRecognition.Classify(_imageURL, OnClassifyGet, OnFail)) { Log.Debug("TestVisualRecognition.Classify()", "Classify image failed!"); } while (!_classifyGetTested) { yield return(null); } // Classify post image Log.Debug("TestVisualRecognition.RunTest()", "Attempting to classify via image on file system"); string imagesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_to_classify.jpg"; string[] owners = { "IBM", "me" }; string[] classifierIDs = { "default", _classifierID }; if (!_visualRecognition.Classify(OnClassifyPost, OnFail, imagesPath, owners, classifierIDs, 0.5f)) { Log.Debug("TestVisualRecognition.Classify()", "Classify image failed!"); } while (!_classifyPostTested) { yield return(null); } // Detect faces get Log.Debug("TestVisualRecognition.RunTest()", "Attempting to detect faces via URL"); if (!_visualRecognition.DetectFaces(_imageURL, OnDetectFacesGet, OnFail)) { Log.Debug("TestVisualRecognition.DetectFaces()", "Detect faces failed!"); } while (!_detectFacesGetTested) { yield return(null); } // Detect faces post image Log.Debug("TestVisualRecognition.RunTest()", "Attempting to detect faces via image"); string faceExamplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/obama.jpg"; if (!_visualRecognition.DetectFaces(OnDetectFacesPost, OnFail, faceExamplePath)) { Log.Debug("TestVisualRecognition.DetectFaces()", "Detect faces failed!"); } while (!_detectFacesPostTested) { yield return(null); } #if DELETE_TRAINED_CLASSIFIER #region Delay Runnable.Run(Delay(_delayTime)); while (_isWaitingForDelay) { yield return(null); } #endregion // Delete classifier by ID Log.Debug("TestVisualRecognition.RunTest()", "Attempting to delete classifier"); if (!_visualRecognition.DeleteClassifier(OnDeleteClassifier, OnFail, _classifierToDelete)) { Log.Debug("TestVisualRecognition.DeleteClassifier()", "Failed to delete classifier!"); } while (!_deleteClassifierTested) { yield return(null); } #endif Log.Debug("TestVisualRecognition.RunTest()", "Visual Recogition tests complete"); yield break; }
public override IEnumerator RunTest() { LogSystem.InstallDefaultReactors(); try { VcapCredentials vcapCredentials = new VcapCredentials(); fsData data = null; // Get credentials from a credential file defined in environmental variables in the VCAP_SERVICES format. // See https://www.ibm.com/watson/developercloud/doc/common/getting-started-variables.html. var environmentalVariable = Environment.GetEnvironmentVariable("VCAP_SERVICES"); var fileContent = File.ReadAllText(environmentalVariable); // Add in a parent object because Unity does not like to deserialize root level collection types. fileContent = Utility.AddTopLevelObjectToJson(fileContent, "VCAP_SERVICES"); // Convert json to fsResult fsResult r = fsJsonParser.Parse(fileContent, out data); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Convert fsResult to VcapCredentials object obj = vcapCredentials; r = _serializer.TryDeserialize(data, obj.GetType(), ref obj); if (!r.Succeeded) { throw new WatsonException(r.FormattedMessages); } // Set credentials from imported credntials Credential credential = vcapCredentials.VCAP_SERVICES["visual_recognition"][TestCredentialIndex].Credentials; _apikey = credential.Apikey.ToString(); _url = credential.Url.ToString(); } catch { Log.Debug("TestVisualRecognition.RunTest()", "Failed to get credentials from VCAP_SERVICES file. Please configure credentials to run this test. For more information, see: https://github.com/watson-developer-cloud/unity-sdk/#authentication"); } // Create credential and instantiate service Credentials credentials = new Credentials(_apikey, _url); _visualRecognition = new VisualRecognition(credentials); _visualRecognition.VersionDate = _visualRecognitionVersionDate; // Get all classifiers Log.Debug("TestVisualRecognition.RunTest()", "Attempting to get all classifiers"); if (!_visualRecognition.GetClassifiers(OnGetClassifiers, OnFail)) { Log.Debug("TestVisualRecognition.GetClassifiers()", "Failed to get all classifiers!"); } while (!_getClassifiersTested) { yield return(null); } #if TRAIN_CLASSIFIER // Train classifier Log.Debug("TestVisualRecognition.RunTest()", "Attempting to train classifier"); string positiveExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_positive_examples.zip"; string negativeExamplesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/negative_examples.zip"; Dictionary <string, string> positiveExamples = new Dictionary <string, string>(); positiveExamples.Add("giraffe", positiveExamplesPath); if (!_visualRecognition.TrainClassifier(OnTrainClassifier, OnFail, "unity-test-classifier-example", positiveExamples, negativeExamplesPath)) { Log.Debug("TestVisualRecognition.TrainClassifier()", "Failed to train classifier!"); } while (!_trainClassifierTested) { yield return(null); } // Find classifier by ID Log.Debug("TestVisualRecognition.RunTest()", "Attempting to find classifier by ID"); if (!_visualRecognition.GetClassifier(OnGetClassifier, OnFail, _classifierID)) { Log.Debug("TestVisualRecognition.GetClassifier()", "Failed to get classifier!"); } while (!_getClassifierTested) { yield return(null); } #endif // Classify get Log.Debug("TestVisualRecognition.RunTest()", "Attempting to get classify via URL"); if (!_visualRecognition.Classify(_imageURL, OnClassifyGet, OnFail)) { Log.Debug("TestVisualRecognition.Classify()", "Classify image failed!"); } while (!_classifyGetTested) { yield return(null); } // Classify post image Log.Debug("TestVisualRecognition.RunTest()", "Attempting to classify via image on file system"); string imagesPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/giraffe_to_classify.jpg"; string[] owners = { "IBM", "me" }; string[] classifierIDs = { "default", _classifierID }; if (!_visualRecognition.Classify(OnClassifyPost, OnFail, imagesPath, owners, classifierIDs, 0.5f)) { Log.Debug("TestVisualRecognition.Classify()", "Classify image failed!"); } while (!_classifyPostTested) { yield return(null); } // Detect faces get Log.Debug("TestVisualRecognition.RunTest()", "Attempting to detect faces via URL"); if (!_visualRecognition.DetectFaces(_imageURL, OnDetectFacesGet, OnFail)) { Log.Debug("TestVisualRecognition.DetectFaces()", "Detect faces failed!"); } while (!_detectFacesGetTested) { yield return(null); } // Detect faces post image Log.Debug("TestVisualRecognition.RunTest()", "Attempting to detect faces via image"); string faceExamplePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/visual-recognition-classifiers/obama.jpg"; if (!_visualRecognition.DetectFaces(OnDetectFacesPost, OnFail, faceExamplePath)) { Log.Debug("TestVisualRecognition.DetectFaces()", "Detect faces failed!"); } while (!_detectFacesPostTested) { yield return(null); } #if DELETE_TRAINED_CLASSIFIER #region Delay Runnable.Run(Delay(_delayTime)); while (_isWaitingForDelay) { yield return(null); } #endregion // Delete classifier by ID Log.Debug("TestVisualRecognition.RunTest()", "Attempting to delete classifier"); if (!_visualRecognition.DeleteClassifier(OnDeleteClassifier, OnFail, _classifierToDelete)) { Log.Debug("TestVisualRecognition.DeleteClassifier()", "Failed to delete classifier!"); } while (!_deleteClassifierTested) { yield return(null); } #endif Log.Debug("TestVisualRecognition.RunTest()", "Visual Recogition tests complete"); yield break; }
void Start() { m_VisualRecognition = new VisualRecognition(); }
void Awake() { Debug.Assert(m_WebCamWidget != null, "[Controller]: Web camera widget is not assigned"); m_VisualRecognition = new VisualRecognition(); }