2016-06-21 5 views
0

Android 용 Microsoft의 Emotion API를 사용하는 데 문제가 있습니다. Face API 실행과 관련하여 아무런 문제가 없습니다. Im은 얼굴 사각형을 가질 수는 있지만 감정 API에서는 작동하지 않습니다. 내장 안드로이드 카메라 자체를 사용하여 이미지를 찍고 있습니다.Microsoft API 관련 문제

private void detectAndFrame(final Bitmap imageBitmap) 
{ 
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 
    imageBitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream); 
    ByteArrayInputStream inputStream = 
      new ByteArrayInputStream(outputStream.toByteArray()); 
    AsyncTask<InputStream, String, List<RecognizeResult>> detectTask = 
      new AsyncTask<InputStream, String, List<RecognizeResult>>() { 
       @Override 
       protected List<RecognizeResult> doInBackground(InputStream... params) { 
        try { 
         Log.e("i","Detecting..."); 
         faces = faceServiceClient.detect(
           params[0], 
           true,   // returnFaceId 
           false,  // returnFaceLandmarks 
           null   // returnFaceAttributes: a string like "age, gender" 
         ); 
         if (faces == null) 
         { 
          Log.e("i","Detection Finished. Nothing detected"); 
          return null; 
         } 
         Log.e("i", 
           String.format("Detection Finished. %d face(s) detected", 
             faces.length)); 
         ImageView imageView = (ImageView)findViewById(R.id.imageView); 
         InputStream stream = params[0]; 
         com.microsoft.projectoxford.emotion.contract.FaceRectangle[] rects = new com.microsoft.projectoxford.emotion.contract.FaceRectangle[faces.length]; 
         for (int i = 0; i < faces.length; i++) { 
          com.microsoft.projectoxford.face.contract.FaceRectangle rect = faces[i].faceRectangle; 
          rects[i] = new com.microsoft.projectoxford.emotion.contract.FaceRectangle(rect.left, rect.top, rect.width, rect.height); 
         } 
         List<RecognizeResult> result; 
         result = client.recognizeImage(stream, rects); 
         return result; 
        } catch (Exception e) { 
         Log.e("e", e.getMessage()); 
         Log.e("e", "Detection failed"); 
         return null; 
        } 
       } 
       @Override 
       protected void onPreExecute() { 
        //TODO: show progress dialog 
       } 
       @Override 
       protected void onProgressUpdate(String... progress) { 
        //TODO: update progress 
       } 
       @Override 
       protected void onPostExecute(List<RecognizeResult> result) { 
        ImageView imageView = (ImageView)findViewById(R.id.imageView); 
        imageView.setImageBitmap(drawFaceRectanglesOnBitmap(imageBitmap, faces)); 
        MediaStore.Images.Media.insertImage(getContentResolver(), imageBitmap, "AnImage" ,"Another image"); 
        if (result == null) return; 
        for (RecognizeResult res: result) { 
         Scores scores = res.scores; 
         Log.e("Anger: ", ((Double)scores.anger).toString()); 
         Log.e("Neutral: ", ((Double)scores.neutral).toString()); 
         Log.e("Happy: ", ((Double)scores.happiness).toString()); 
        } 

       } 
      }; 
    detectTask.execute(inputStream); 
} 

내가 JSON이나 얼굴 사각형 문제의 어떤 종류를 나타내는 오류 POST 요청 (400)가 계속 : 여기에 내가 사용하고있는 코드입니다. 하지만이 문제를 어디서 디버깅해야할지 모르겠습니다.

답변

1

스트림을 두 번 사용하므로 두 번째 스트림이 이미 스트림의 끝 부분에 있습니다. 따라서 스트림을 재설정하거나 직사각형없이 감정 API를 호출 할 수 있습니다 (즉, 얼굴 API 호출을 건너 뜁니다.) 감정 API가 얼굴 사각형을 결정합니다.