-

   rss_rss_hh_new

 - e-mail

 

 -

 LiveInternet.ru:
: 17.03.2011
:
:
: 51

:


: Microsoft Cognitive Services + Unity

, 31 2017 . 09:59 +
!

, REST API , .. -. , VRTech Game- , Unity, Unity-, .




Microsoft Cognitive Services Unity; , HTTP WWW ( - ) , , Google Play.




Microsoft Cognitive Services , , , , .

- , Emotions API. UWP, Unity . , Unity. .

, . , OpenCV. , .

. Emotions API Face API.



. , SubscriptionKey ( ScriptableObject), , .

private IEnumerator CheckEmotions()
{
EmotionService emoServ = new EmotionService(SubscriptionKeys.Instance.EmotionsApiKey);
while (true)
{
yield return new WaitForEndOfFrame();
yield return emoServ.GetEmoInfoCoroutine(_WebCam.Screenshot);
var emotions = emoServ.LastEmotions;
if (emotions != null)
{
_MaxEmotionValue.text = GetMaxEmotionOnScreenshot(emotions);
}
yield return new WaitForSeconds(DELAY);
}
}


subscription key Microsoft

, ? , Rest API. Unity WWW, . .

, , , .

, .

private IEnumerator CreateRecognizeRequestAndSaveResponseCoroutine(
string contentHeader, 
byte[] data)
{
Dictionary headers = new Dictionary();
headers.Add(Constants.SUB_KEY_HEADER, _SubscriptionKey);
headers.Add(Constants.CONTENT_TYPE_HEADER, contentHeader);
WWW request = new WWW(_RecognizeRequestUrl, data, headers);
yield return new WaitUntil(() => request.isDone);
ParseEmotionsFromJson(request.text);
}


, , . , , . . , , - . , Unity Ads . , , .

, . , WWW . System.Net ( 2.0, Unity ). , SSL-, , . - , , .

( )
private void CreateRecognizeRequest()
{
 Clear();
 _Thread = new Thread(Run);
 _Thread.Start(); 
}
private void Run()
{
 WebHeaderCollection headers = new WebHeaderCollection();
 headers.Add(Constants.SUB_KEY_HEADER, _SubscriptionKey);
 var request = HttpWebRequest.Create(_RecognizeRequestUrl);
 request.ContentType = _ContentHeader;
 request.Headers = headers;
 request.ContentLength = _Data.Length;
 request.Method = WebRequestMethods.Http.Post;
 var dataStream = request.GetRequestStream();
 dataStream.Write(_Data, 0, _Data.Length);
 dataStream.Close();
 var response = request.GetResponse();
 dataStream = response.GetResponseStream();
 StreamReader reader = new StreamReader(dataStream);
 string responseString = reader.ReadToEnd();

 reader.Close();
 dataStream.Close();
 response.Close();
 Debug.Log(responseString);
 if (!TryParseEmotionsFromJson(responseString))
 {
  Run();
 }
 else
 {
  _IsDataReady = true;
 }
}


Face API. .





Face API , Emotions API. , , Emotions API . , ( ) Face API, Emotions API.

, Microsoft Cognitive Services. Demo , EmotionService . , (, RectTransform )

, Github . ( )

Unity Moscow Meetup #3


7 Unity . Unity ! , ,

, , :
VK: vk.com/unimosmeet
FB: www.facebook.com/groups/unimosmeet


Unity VRTech. Unity Moscow Meetup. , , .
Original source: habrahabr.ru (comments, light).

https://habrahabr.ru/post/329866/

:  

: [1] []
 

:
: 

: ( )

:

  URL