Assets/Watson/Scripts/Services/VisualRecognition/VisualRecognition.cs
/// <summary>
/// Add an image to a collection.
/// </summary>
/// <param name="callback">The callback.</param>
/// <param name="collectionID">The identifier of the collection to add images to.</param>
/// <param name="imageData">The byte[] data of the image to add.</param>
/// <param name="metadata">Optional json metadata associated with the specified image.</param>
/// <param name="customData">Optional custom data.</param>
/// <returns></returns>
Add an image to a collection.
Add an image to a collection .
public bool AddCollectionImage(OnAddCollectionImage callback, string collectionID, byte[] imageData, string filename, string metadata = null, string customData = null)
        {
            if (callback == null)
                throw new ArgumentNullException("callback");
            if (string.IsNullOrEmpty(collectionID))
                throw new ArgumentNullException("collectionID");
            if (imageData == default(byte[]))
                throw new WatsonException("Image data is required!");
            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!");
            RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, string.Format(SERVICE_COLLECTION_IMAGES, collectionID));
            if (connector == null)
                return false;
            AddCollectionImageReq req = new AddCollectionImageReq();
            req.Callback = callback;
            req.CollectionID = collectionID;
            req.ImageData = imageData;
            req.Metadata = metadata;
            req.Data = customData;
            req.Parameters["api_key"] = mp_ApiKey;
            req.Parameters["version"] = VisualRecognitionVersion.Version;
            req.Forms = new Dictionary<string, RESTConnector.Form>();
            req.Forms["image_file"] = new RESTConnector.Form(imageData, filename, GetMimeType(filename));
            req.Forms["metadata"] = new RESTConnector.Form(Encoding.UTF8.GetBytes(metadata), "application/json");
            req.Timeout = 20.0f * 60.0f;
            req.OnResponse = OnAddCollectionImageResp;
            return connector.Send(req);
		}
public bool AddCollectionImage ( OnAddCollectionImage callback , string collectionID , byte [ ] imageData , string filename , string metadata = null , string customData = null ) { if ( callback == null ) throw new ArgumentNullException ( " " ) ; if ( string . IsNullOrEmpty ( collectionID ) ) throw new ArgumentNullException ( " " ) ; if ( imageData == default ( byte [ ] ) ) throw new WatsonException ( " " ) ; if ( string . IsNullOrEmpty ( mp_ApiKey ) ) mp_ApiKey = Config . Instance . GetAPIKey ( SERVICE_ID ) ; if ( string . IsNullOrEmpty ( mp_ApiKey ) ) throw new WatsonException ( " " ) ; RESTConnector connector = RESTConnector . GetConnector ( SERVICE_ID , string . Format ( SERVICE_COLLECTION_IMAGES , collectionID ) ) ; if ( connector == null ) return false ; AddCollectionImageReq req = new AddCollectionImageReq ( ) ; req . Callback = callback ; req . CollectionID = collectionID ; req . ImageData = imageData ; req . Metadata = metadata ; req . Data = customData ; req . Parameters [ " " ] = mp_ApiKey ; req . Parameters [ " " ] = VisualRecognitionVersion . Version ; req . Forms = new Dictionary < string , RESTConnector . Form > ( ) ; req . Forms [ " " ] = new RESTConnector . Form ( imageData , filename , GetMimeType ( filename ) ) ; req . Forms [ " " ] = new RESTConnector . Form ( Encoding . UTF8 . GetBytes ( metadata ) , " " ) ; req . Timeout = 20.0f * 60.0f ; req . OnResponse = OnAddCollectionImageResp ; return connector . Send ( req ) ; }
Add an image to a collection.
Add an image to a collection .
None
callback
OnAddCollectionImage
None
collectionID
string
The identifier of the collection to add images to.
The identifier of the collection to add images to .
imageData
byte[]
The byte[] data of the image to add.
The byte [] data of the image to add .
filename
string
metadata
string
Optional json metadata associated with the specified image.
Optional json metadata associated with the specified image .
customData
string
Optional custom data.
Optional custom data .