0

そのため、Microsoft の Emotion API for Android の使用に問題があります。Face API の実行に関して問題はありません。顔の四角形を取得できますが、感情APIで機能させることができません。内蔵の Android カメラ自体を使用して画像を撮影しています。私が使用しているコードは次のとおりです。

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 Request 400 が引き続き表示されます。しかし、この問題のデバッグをどこから開始すればよいかわかりません。

4

1 に答える 1

1

ストリームを 2 回使用しているため、2 回目はすでにストリームの最後にいます。そのため、ストリームをリセットするか、単に四角形なしで感情 API を呼び出す (つまり、顔 API の呼び出しをスキップする) ことができます。感情 API が顔の四角形を決定します。

于 2016-06-21T08:31:32.247 に答える