Assets/Watson/Scripts/Services/VisualRecognition/VisualRecognition.cs
/// <summary>
/// Add an image to a collection via image path on file system and metadata as dictionary.
/// </summary>
/// <param name="callback">The callback.</param>
/// <param name="collectionID">The identifier of the collection to add images to.</param>
/// <param name="imagePath">The path in the filesystem of the image to add.</param>
/// <param name="metadata">Optional Dictionary key value pairs of metadata associated with the specified image.</param>
/// <param name="customData">Optional custom data.</param>
/// <returns>Returns true if succeess, false if failure.</returns>
Add an image to a collection via image path on file system and metadata as dictionary.
Add an image to a collection via image path on file system and metadata as dictionary .
public bool AddCollectionImage(OnAddCollectionImage callback, string collectionID, string imagePath, Dictionary<string, string> metadata = null, string customData = null)
        {
            if (callback == null)
                throw new ArgumentNullException("callback");
            if (string.IsNullOrEmpty(collectionID))
                throw new ArgumentNullException("collectionID");
            if (string.IsNullOrEmpty(imagePath))
                throw new ArgumentNullException("imagePath");
            if (string.IsNullOrEmpty(mp_ApiKey))
                mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID);
            if (string.IsNullOrEmpty(mp_ApiKey))
                throw new WatsonException("No API Key was found!");
            byte[] imageData = null;
            if (!string.IsNullOrEmpty(imagePath))
            {
                if (LoadFile != null)
                {
                    imageData = LoadFile(imagePath);
                }
                else
                {
#if !UNITY_WEBPLAYER
                    imageData = File.ReadAllBytes(imagePath);
#endif
                }
                if (imageData == null)
                    Log.Error("VisualRecognition", "Failed to upload {0}!", imagePath);
            }
            return AddCollectionImage(callback, collectionID, imageData, Path.GetFileName(imagePath), GetMetadataJson(metadata), customData);
        }
public bool AddCollectionImage ( OnAddCollectionImage callback , string collectionID , string imagePath , Dictionary < string , string > metadata = null , string customData = null ) { if ( callback == null ) throw new ArgumentNullException ( " " ) ; if ( string . IsNullOrEmpty ( collectionID ) ) throw new ArgumentNullException ( " " ) ; if ( string . IsNullOrEmpty ( imagePath ) ) throw new ArgumentNullException ( " " ) ; if ( string . IsNullOrEmpty ( mp_ApiKey ) ) mp_ApiKey = Config . Instance . GetAPIKey ( SERVICE_ID ) ; if ( string . IsNullOrEmpty ( mp_ApiKey ) ) throw new WatsonException ( " " ) ; byte [ ] imageData = null ; if ( ! string . IsNullOrEmpty ( imagePath ) ) { if ( LoadFile != null ) { imageData = LoadFile ( imagePath ) ; } else { if ! UNITY_WEBPLAYER imageData = File . ReadAllBytes ( imagePath ) ; endif } if ( imageData == null ) Log . Error ( " " , " " , imagePath ) ; } return AddCollectionImage ( callback , collectionID , imageData , Path . GetFileName ( imagePath ) , GetMetadataJson ( metadata ) , customData ) ; }
Add an image to a collection via image path on file system and metadata as dictionary.
Add an image to a collection via image path on file system and metadata as dictionary .
Returns true if succeess, false if failure.
Returns true if succeess false if failure .
callback
OnAddCollectionImage
None
collectionID
string
The identifier of the collection to add images to.
The identifier of the collection to add images to .
imagePath
string
The path in the filesystem of the image to add.
The path in the filesystem of the image to add .
metadata
Dictionary<string, string>
Optional Dictionary key value pairs of metadata associated with the specified image.
Optional Dictionary key value pairs of metadata associated with the specified image .
customData
string
Optional custom data.
Optional custom data .