0

얼굴 인식으로 내 얼굴을 찾았 으면 3 초 후 서클이 사라집니다. 일부 휴대 전화에서만 발생하므로 왜 일어나는 지 확신 할 수 없습니다. 내 코드는 꽤 정형화 된 코드입니다.Google 모바일 비전 : 3 초 후 얼굴 인식이 중지됩니다.

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_detect); 

    detector = new FaceDetector.Builder(getApplicationContext()) 
      .setTrackingEnabled(false) 
      .setProminentFaceOnly(true) 
      .setMode(FaceDetector.FAST_MODE) 
      .setMinFaceSize((float) 0.60) 
      .setLandmarkType(FaceDetector.ALL_CLASSIFICATIONS) 
      .setClassificationType(FaceDetector.ALL_CLASSIFICATIONS) 

      .build(); 


    initViews(); 

} 

private void initViews() { 
    imgTakePicture = (ImageView) findViewById(R.id.imgTakePic); 
    btnTakePicture = (Button) findViewById(R.id.btnTakePicture); 
    txtSampleDesc = (TextView) findViewById(R.id.txtSampleDescription); 
    txtTakenPicDesc = (TextView) findViewById(R.id.textView); 

    btnTakePicture.setOnClickListener(this); 
    imgTakePicture.setOnClickListener(this); 


} 


@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    Log.d(TAG, "onActivityResult: this is resyult"); 
    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) { 
     launchMediaScanIntent(); 
     try { 
      processCameraPicture(); 
     } catch (Exception e) { 
      Toast.makeText(getApplicationContext(), "Failed to load Image", Toast.LENGTH_SHORT).show(); 
     } 
    } 
} 

private void launchMediaScanIntent() { 
    Log.d(TAG, "launchMediaScanIntent: "); 
    Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); 
    mediaScanIntent.setData(imageUri); 
    this.sendBroadcast(mediaScanIntent); 
} 

private void startCamera() { 
    Log.d(TAG, "startCamera: "); 
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
    Log.d(TAG, "startCamera: 2"); 
    File photo = new File(Environment.getExternalStorageDirectory(), "/videoDIARY/ReferencePic/photo.jpg"); 

    imageUri = Uri.fromFile(photo); 

    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri); 

    startActivityForResult(intent, CAMERA_REQUEST); 

} 

편집 : 좋아요,이 모든 것은 기기 방향에 관한 것입니다. 가로 모드의 모든 장치에서 제대로 작동하며 세로 모드의 일부 장치에서만 작동합니다. 아직도 해결하려고하면, 내가 고칠 때 업데이 트됩니다!

+0

휴대 전화의 차이점은 무엇입니까? Perfomance, Android 버전 등? –

+0

@ MaximTsybanov, 내 Moto G5 Plus, andorid 버전 7.0에서 작동하지만 HTC 6.0에서는 작동하지만 5.0, 5.1, 6.0 및 6.1이 혼합 된 Samsung 또는 Lg에서는 작동하지 않습니다. 휴대 전화의 일반 카메라 애플리케이션에서 동일한 작업을 수행했기 때문에 폰 페이셜 감지 또는 Google Play Vision과 관련이있는 것으로 보입니다. –

답변

0

좋아요, 그래서 안면 감지와 관련이 없으며 Android가 Camera Intent Images를 저장하는 방법과 관련이 있습니다. 기본적으로 방향이 혼란 스럽기 때문에 너비와 높이를 확인하고 올바르게하고 있는지 확인하고 그렇지 않은 경우 회전시켜야합니다. 다음은 내가 확인한 방법입니다.

private Bitmap decodeBitmapUri(Context ctx, Uri uri) throws FileNotFoundException { 
    Log.d(TAG, "decodeBitmapUri: "); 
    //Toast.makeText(this, "1o" , Toast.LENGTH_LONG).show(); 
    Log.d(TAG, "initViews1: face detector is ============================ " + detector.isOperational()); 
    int targetW = 300; 
    int targetH = 300; 
    BitmapFactory.Options bmOptions = new BitmapFactory.Options(); 
    bmOptions.inJustDecodeBounds = true; 
    bmOptions.inPreferredConfig=Bitmap.Config.RGB_565; 
    BitmapFactory.decodeStream(ctx.getContentResolver().openInputStream(uri), null, bmOptions); 
    android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo(); 
    android.hardware.Camera.getCameraInfo(Camera.CameraInfo.CAMERA_FACING_FRONT, info); 
    int rotation = this.getWindowManager().getDefaultDisplay().getRotation(); 
    int orientation = this.getResources().getConfiguration().orientation; 
    Log.d(TAG, "decodeBitmapUri: OREINTATION is ==================== " + orientation); 

    Log.d(TAG, "decodeBitmapUri: CAMERA ROTATION ========================= " + rotation); 
    //Camera.Size size = android.hardware.Camera.get 


    int photoW = bmOptions.outWidth; 
    Log.d(TAG, "decodeBitmapUri: width: " + photoW); 
    int photoH = bmOptions.outHeight; 
    Log.d(TAG, "decodeBitmapUri: height: " + photoH); 
    Log.d(TAG, "decodeBitmapUri: 4"); 
    //Toast.makeText(this, "11" , Toast.LENGTH_LONG).show(); 

    int scaleFactor = Math.min(photoW/targetW, photoH/targetH); 
    bmOptions.inJustDecodeBounds = false; 
    bmOptions.inSampleSize = scaleFactor; 

    /*this is because some phones default a camera Intent to landscape no matter how the phone is held 
    * so we check for camera orienatation, then check to see if width is greater than height 
    * */ 

    if(orientation == 1 && (photoW > photoH)){ 
     return rotate(BitmapFactory.decodeStream(ctx.getContentResolver() 
       .openInputStream(uri), null, bmOptions)); 
    } 


    return BitmapFactory.decodeStream(ctx.getContentResolver() 
      .openInputStream(uri), null, bmOptions); 
} 

public static Bitmap rotate(Bitmap bitmap){ 
    int w = bitmap.getWidth(); 
    int h = bitmap.getHeight(); 

    Matrix mtx = new Matrix(); 
    mtx.postRotate(270); 

    return Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, true); 
} 
관련 문제