コード例 #1
0
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_SELECT_IMAGE) {
      if (resultCode == RESULT_OK) {
        mBitmap = ImageHelper.loadSizeLimitedBitmapFromUri(data.getData(), getContentResolver());
        if (mBitmap != null) {
          View originalFaces = findViewById(R.id.all_faces);
          originalFaces.setVisibility(View.VISIBLE);

          // Show the result of face grouping.
          ListView groupedFaces = (ListView) findViewById(R.id.grouped_faces);
          FaceGroupsAdapter faceGroupsAdapter = new FaceGroupsAdapter(null);
          groupedFaces.setAdapter(faceGroupsAdapter);

          // Put the image into an input stream for detection.
          ByteArrayOutputStream output = new ByteArrayOutputStream();
          mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, output);
          ByteArrayInputStream inputStream = new ByteArrayInputStream(output.toByteArray());

          setAllButtonsEnabledStatus(false);

          addLog("Request: Detecting in image " + data.getData());
          // Start a background task to detect faces in the image.
          new DetectionTask().execute(inputStream);
        }
      }
    }
  }
コード例 #2
0
 public void addFaces(Face[] detectionResult) {
   if (detectionResult != null) {
     List<Face> detectedFaces = Arrays.asList(detectionResult);
     for (Face face : detectedFaces) {
       faces.add(face);
       try {
         Bitmap faceThumbnail = ImageHelper.generateFaceThumbnail(mBitmap, face.faceRectangle);
         faceThumbnails.add(faceThumbnail);
         faceIdThumbnailMap.put(face.faceId, faceThumbnail);
       } catch (IOException e) {
         // Show the exception when generating face thumbnail fails.
         TextView textView = (TextView) findViewById(R.id.info);
         textView.setText(e.getMessage());
       }
     }
   }
 }