Mobile Vision에서 Android의 ML Kit로 이전

이 문서에서는 Google Mobile Vision (GMV)에서 Android의 ML Kit로 프로젝트를 이전하는 데 필요한 단계를 설명합니다.

전반적인 API 변경사항

이러한 변경사항은 모든 API에 적용됩니다.

  • GMV API는 SparseArray<T> 결과를 동기식으로 반환합니다. ML Kit API는 Google Play 서비스 Task API를 사용하여 결과를 비동기식으로 반환합니다.
  • GMV는 API 노출 영역에서 isOperational() 호출을 사용하여 모듈이 성공적으로 다운로드되어 사용할 준비가 되었는지 나타냅니다. ML Kit에는 이러한 방법이 없습니다. 모듈이 다운로드되지 않았다면 ML Kit에서 MlKitException.UNAVAILABLE 예외가 발생합니다. 이 예외를 포착하여 다음 프레임을 처리하거나 시간 제한을 설정하고 현재 프레임으로 다시 시도할 수 있습니다.
  • GMV 메서드는 입력에 Frame를 사용합니다. ML Kit는 InputImage를 사용합니다.
  • GMV는 여러 감지 및 결과 필터링을 수행하기 위한 MultiDetector, MultiProcessor, FocusingProcessor 프레임워크를 제공합니다. ML Kit는 이러한 메커니즘을 제공하지 않지만 원하는 경우 개발자가 동일한 기능을 구현할 수 있습니다.

Gradle 가져오기 업데이트

다음 표에 따라 모듈(앱 수준) Gradle 파일(일반적으로 app/build.gradle)에서 ML Kit Android 라이브러리의 종속 항목을 업데이트합니다.

API GMV 아티팩트 ML Kit 아티팩트
FaceDetector com.google.android.gms:play-services-vision:x.x.x com.google.android.gms:play-services-mlkit-face-detection:17.1.0
BarcodeDetector com.google.android.gms:play-services-vision:x.x.x com.google.android.gms:play-services-mlkit-barcode-scanning:18.3.0
TextRecognition com.google.android.gms:play-services-vision:x.x.x com.google.android.gms:play-services-mlkit-text-recognition:19.0.0
CameraSource com.google.android.gms:play-services-vision:x.x.x com.google.mlkit:camera:16.0.0-beta3

API 변경사항

이 섹션에서는 각 Vision API의 해당하는 GMV 및 ML Kit 클래스와 메서드를 설명하고 API를 초기화하는 방법을 보여줍니다.

FaceDetector

다음 예와 같이 초기화를 다시 코딩합니다.

총거래액(GMV)

detector = new FaceDetector.Builder(context)
    .setMode(FaceDetector.ACCURATE_MODE)
    .setLandmarkType(FaceDetector.ALL_LANDMARKS)
    .setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)
    .build();

ML Kit

FaceDetectorOptions options = new FaceDetectorOptions.Builder()
    .setPerformanceMode(FaceDetectorOptions.PERFORMANCE_MODE_ACCURATE)
    .setLandmarkMode(FaceDetectorOptions.LANDMARK_MODE_ALL)
    .setClassificationMode(FaceDetectorOptions.CLASSIFICATION_MODE_ALL)
    .build();

detector = FaceDetection.getClient(options);

다음 클래스 및 메서드 이름을 변경합니다.

android.gms.vision.face mlkit.vision.face
FaceDetector FaceDetector
SparseArray<Face> detect(Frame frame) Task<List<Face>> process(@NonNull InputImage image)
FaceDetector.Builder.setClassificationType(int classificationType) FaceDetectorOptions.Builder.setClassificationMode(int classificationMode)
NO_CLASSIFICATIONS, ALL_CLASSIFICATIONS CLASSIFICATION_MODE_NONE, CLASSIFICATION_MODE_ALL
FaceDetector.Builder.setLandmarkType(int landmarkType) FaceDetectorOptions.Builder.setLandmarkMode(int landmarkMode)
NO_LANDMARKS, ALL_LANDMARKS, CONTOUR_LANDMARKS LANDMARK_MODE_NONE, LANDMARK_MODE_ALL

#setContourMode를 사용하여 GMV CONTOUR_LANDMARKS 대체

FaceDetector.Builder.setTrackingEnabled(boolean trackingEnabled) FaceDetectorOptions.Builder.enableTracking()
FaceDetector.Builder.setMinFaceSize(float proportionalMinFaceSize) FaceDetectorOptions.Builder.setMinFaceSize(float minFaceSize)
FaceDetector.Builder.setMode(int mode) FaceDetectorOptions.Builder.setPerformanceMode(int performanceMode)
FAST_MODE, ACCURATE_MODE PERFORMANCE_MODE_FAST, PERFORMANCE_MODE_ACCURATE
FaceDetector.Builder.setProminentFaceOnly(boolean prominentFaceOnly) 이 기능은 얼굴 윤곽 모드가 적용됩니다.
Face Face
Contour FaceContour
Landmark FaceLandmark
Face.getContours() Face.getAllContours()
Face.getEulerY() Face.getHeadEulerAngleY()
Face.getEulerZ() Face.getHeadEulerAngleZ()
Face.getId() Face.getTrackingId()
Face.getIsLeftEyeOpenProbability() Face.getLeftEyeOpenProbability()
Face.getIsRightEyeOpenProbability() Face.getRightEyeOpenProbability()
Face.getIsSmilingProbability() Face.getSmilingProbability()
Face.getLandmarks() Face.getLandmark(int landmarkType)
Face.getPosition()
Face.getHeight()
Face.getWidth()
Face.getBoundingBox()

BarcodeDetector

다음 예와 같이 초기화를 다시 코딩합니다.

총거래액(GMV)

barcodeDetector = new BarcodeDetector.Builder(context).build());

ML Kit

barcodeScanner = BarcodeScanning.getClient();

다음 클래스 및 메서드 이름을 변경합니다.

android.gms.vision.barcode mlkit.vision.barcode
BarcodeDetector BarcodeScanner
SparseArray<Barcode> detect(Frame frame) Task<List<Barcode>> process(@NonNull InputImage image)
Barcode Barcode

TextRecognition

다음 예와 같이 초기화를 다시 코딩합니다.

총거래액(GMV)

textRecognizer = new TextRecognizer.Builder(context).build();

ML Kit

textRecognizer = TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS);

다음 클래스 및 메서드 이름을 변경합니다.

android.gms.vision.text mlkit.vision.text
TextRecognizer TextRecognizer
SparseArray<TextBlock> detect(Frame frame) Task<Text> process(@NonNull InputImage image)
SparseArray<TextBlock> Text
Line Line
TextBlock TextBlock
Element Element
getLanguage() getRecognizedLanguage()
getBoundingBox() getBoundingBox()
getCornerPoints() getCornerPoints()
TextBlock.getComponents() TextBlock.getLines()
TextBlock.getValue() TextBlock.getText()
Element.getValue() Element.getText()

CameraSource

Google Mobile Vision에서 제공하는 CameraSource 라이브러리를 사용하는 경우 앱이 최소 SDK 버전 21 이상에서 실행되는 경우 ML Kit의 CameraXSource 라이브러리로 쉽게 이전할 수 있습니다.

다음 클래스 및 메서드 이름을 변경합니다.

android.gms.vision mlkit.vision.camera
CameraSource CameraSourceConfig
CameraSource.Builder CameraSourceConfig.Builder
CameraSource.Builder.setAutoFocusEnabled CameraX를 사용할 때는 자동 초점이 기본적으로 제공됩니다.
CameraSource.Builder.setFacing CameraSourceConfig.Builder.setCameraFacing
CameraSource.Builder.setFocusMode CameraX를 사용할 때는 자동 초점이 기본적으로 제공됩니다.
CameraSource.Builder.setRequestedFps 지원이 중단되었습니다.
CameraSource.Builder.setRequestedPreviewSize CameraSourceConfig.Builder.setRequestedPreviewSize
CameraSource CameraXSource
new CameraSource.Builder(mContext, detector)....build(); CameraXSource(CameraSourceConfig, PreviewView)
getCameraFacing() getCameraFacing()
getPreviewSize() getPreviewSize()
release() close()
start(SurfaceHolder surfaceHolder) start() // The previewview is set in the CameraSourceConfig
start() start()
stop() stop()
Detector.Processor DetectionTaskCallback
receiveDetections(Detections<T> detections) void onDetectionTaskReceived(@NonNull Task<ResultT> detectionTask);
release() 내부적으로 처리
CameraSource.PictureCallback 지원 중단됨
CameraSource.ShutterCallback 지원 중단됨

지원 받기

문제가 발생할 경우 문의할 수 있는 채널이 안내된 커뮤니티 페이지를 확인하세요.