추적 용으로 시각적 API를 사용하고 있습니다. 얼굴 위치 기준으로 마스크를 적용했습니다. 전 카메라에서 사진을 찍을 때 카메라 소스를 호출합니다. 사진()은 이미지를 저장합니다. 저는 삼성과 같은 일부 장치에서 이미지 회전 문제를 겪고 있으며 마스크와 얼굴을 보여줍니다. Exif 클래스를 사용하여 이미지의 방향을 가져 오지만 이미지를 회전시킬 수 없으므로 항상 0을 반환합니다. getOrientation 및 이미지 회전에 다음 클래스를 사용하고 있습니다.camerasource.takePicture() 일부 기기에서 회전 된 이미지 저장
public class ExifUtils {
public Bitmap rotateBitmap(String src, Bitmap bitmap) {
try {
int orientation = getExifOrientation(src);
if (orientation == 1) {
return bitmap;
}
Matrix matrix = new Matrix();
switch (orientation) {
case 2:
matrix.setScale(-1, 1);
break;
case 3:
matrix.setRotate(180);
break;
case 4:
matrix.setRotate(180);
matrix.postScale(-1, 1);
break;
case 5:
matrix.setRotate(90);
matrix.postScale(-1, 1);
break;
case 6:
matrix.setRotate(90);
break;
case 7:
matrix.setRotate(-90);
matrix.postScale(-1, 1);
break;
case 8:
matrix.setRotate(-90);
break;
default:
return bitmap;
}
try {
Bitmap oriented = Bitmap.createBitmap(bitmap, 0, 0,
bitmap.getWidth(), bitmap.getHeight(), matrix, true);
bitmap.recycle();
return oriented;
} catch (OutOfMemoryError e) {
e.printStackTrace();
return bitmap;
}
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
private int getExifOrientation(String src) throws IOException {
int orientation = 1;
try {
if (Build.VERSION.SDK_INT >= 5) {
Class<?> exifClass = Class
.forName("android.media.ExifInterface");
Constructor<?> exifConstructor = exifClass
.getConstructor(new Class[]{String.class});
Object exifInstance = exifConstructor
.newInstance(new Object[]{src});
Method getAttributeInt = exifClass.getMethod("getAttributeInt",
new Class[]{String.class, int.class});
Field tagOrientationField = exifClass
.getField("TAG_ORIENTATION");
String tagOrientation = (String) tagOrientationField.get(null);
orientation = (Integer) getAttributeInt.invoke(exifInstance,
new Object[]{tagOrientation, 1});
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (Fragment.InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (java.lang.InstantiationException e) {
e.printStackTrace();
}
return orientation;
}
}
나는 비전 API에서이 issue 어떤 해결책이 발견했다.
비전 API 문제에 대한 덧글을 참조하십시오. 프레임 메타 데이터에서 방향을 얻을 수 있습니다. – pm0733464
감사합니다. @ pm0733464 예제를 제공해주십시오. –
나는 내 문제를 풀어 내 비전 API를 issue.https : //github.com/googlesamples/android-vision/issues/124에 대한 덧글을 참조하십시오 –