private bool DetectFaces(OnDetectFaces callback, string imagePath, byte[] imageData = default(byte[])) { RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, SERVICE_DETECT_FACES); if (connector == null) { return(false); } DetectFacesReq req = new DetectFacesReq(); req.Callback = callback; req.Timeout = REQUEST_TIMEOUT; req.OnResponse = OnDetectFacesResp; req.Parameters["api_key"] = mp_ApiKey; req.Parameters["version"] = VisualRecognitionVersion.Version; if (imageData != null) { req.Headers["Content-Type"] = "application/x-www-form-urlencoded"; req.Send = imageData; } return(connector.Send(req)); }
/// <summary> /// Detects faces in a given image URL. /// </summary> /// <returns><c>true</c>, if faces was detected, <c>false</c> otherwise.</returns> /// <param name="url">URL.</param> /// <param name="callback">Callback.</param> public bool DetectFaces(string url, OnDetectFaces callback) { if (string.IsNullOrEmpty(url)) { throw new ArgumentNullException("url"); } if (callback == null) { throw new ArgumentNullException("callback"); } if (string.IsNullOrEmpty(mp_ApiKey)) { mp_ApiKey = Config.Instance.GetAPIKey(SERVICE_ID); } if (string.IsNullOrEmpty(mp_ApiKey)) { throw new WatsonException("FindClassifier - VISUAL_RECOGNITION_API_KEY needs to be defined in config.json"); } RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, SERVICE_DETECT_FACES); if (connector == null) { return(false); } DetectFacesReq req = new DetectFacesReq(); req.Callback = callback; req.OnResponse = OnDetectFacesResp; req.Parameters["api_key"] = mp_ApiKey; req.Parameters["url"] = url; req.Parameters["version"] = VisualRecognitionVersion.Version; return(connector.Send(req)); }