[Vision] 내가 보려고 정리하는 Apple 머신러닝: Vision Framework

2025. 6. 26. 09:10ML, Spatial Computing

Apple이 프레임워크 수준에서 제공하는 온디바이스 머신러닝 (Machine Learning) API는 총 다섯가지가 있습니다.
Vision, Natural Language, Speech, Sound, 그리고 나온지 얼마되지 않은 Translation까지.

오늘은 이 다섯가지 프레임워크 중에서 앱에서 Computer Vision을 수행할 수 있도록 도와주는 API, Vision에 대해 알아보고자 합니다.

 

Vision | Apple Developer Documentation

Apply computer vision algorithms to perform a variety of tasks on input images and videos.

developer.apple.com

Vision은 Apple 플랫폼에서 이미지 또는 비디오의 객체 인식이나 분석 기능을 제공하는 프레임워크입니다.

WWDC25 기준으로 Vision에서는 총 33가지의 request API를 제공하고 있습니다.
이 request API는 Swift Concurrency와 Swift 6에 대한 지원을 포함하고 있어, Apple Platform에서 동작하는 어떤 앱을 만들 때 Swift 코드만으로 쉽게 ML - Computer Vision 기능을 넣을 수 있다는 특징이 있죠.

🧐 Vision은 어떠한 방식으로 동작하는거지?
쉽게 말해, Vision Request는 이미지에 대해 머신러닝 모델 (= Vision)에게 질문을 던지는 개념입니다.
(예를 들어, "이 이미지에서 사람의 얼굴은 어디에 위치하고 있어?" "이 이미지에 뭐라고 쓰여있는거야?" "이 이미지는 무슨 동물이야?"와 같은 내용이죠.)
-
Vision은 위의 요청 (request)실행 (perform) 함으로써 관찰 (Observations)의 형태로 답변을 제공합니다.
우리는 이 답변 데이터를 바탕으로 (어느정도 가공을 거친 이후에) 앱의 UI 수준에서 사용자에게 잘 제공해주기만 하면 됩니다.

결론!
모든 Vision Framework는 어떤 이미지를 바탕으로 Vision이라는 애플의 온디바이스 머신러닝 모델에게 요청 (request)을 보내고
-> 머신러닝 모델은 이 요청을 수행 (perform)하고
-> 이 수행된 결과가 관찰 (Observations)의 형태로 제공되는 흐름으로 이어집니다. (이때 관찰은 비동기 (await)로, 에러 발생 가능성 (try)을 염두해둡니다.)

그렇다면 Vision Framework에서 총 33가지의 request API를 제공하고 있다는 말이 의미하는 것은
우리가 Vision Model에게 하나의 이미지를 가지고 요청 (request)을 보낼 수 있는 종류가 33가지나 된다는 것입니다.
*어떤 요청이던 request -> perform -> observations의 플로우를 갖고 있는 것은 동일하고. 이름만 조금씩 달라지는 형태입니다.

그렇다면, Vision을 배운다는 것의 진정한 의미는 "Vision이 제공하는 33가지의 request는 무엇이 있는지"를 알아보는 것이 되겠네요!
한번 배워봅시다.

 

정적 이미지 분석 (Still-image analysis)

1. ClassifyImageRequest 

  • 이미지의 전체적인 내용 (풍경, 동물, 사람 등)을 분류해줍니다. (A request to classify an image)
  • 결과값은 ClassificationObservation이고, identifier 속성으로 예측된 라벨이 무엇인지 확인할 수 있습니다. (예측 가능한 라벨은 1303개이고, 
  • supportedIdentifiers라는 String 타입의 Array로 Apple이 해당 모델에서 제공하는 예측 가능한 라벨 목록을 확인할 수 있습니다. -> 목록은 여기에서 확인할 수 있죠!)
  • cropAndScaleAction에서 옵셔널로 요청을 보내기 전, 이미지의 크기/비율 처리 방식을 설정할 수 있습니다. (처리 방식은 ImageCropAndScaleAction enum 파일에 정의되어있습니다.)

 

2. DetectLensSmudgeRequest [WWDC25 Update!] 

  • 사진 또는 비디오 촬영 프레임에서 렌즈에 얼룩이 있는지를 감지합니다. (A request that detects a smudge on a lens from an image or video frame capture)
  • SmudgeObservation 타입의 결과값이 도출되고, 0~1 사이 Float 타입의 confidence를 통해 얼룩 감지에 대한 신뢰 수준을 확인할 수 있습니다. (1에 가까울수록 얼룩이 감지되었다는 것)

이미지 시퀀스 분석 (Image sequence analysis)

3. GeneratePersonSegmentationRequest  

  • 이미지에서 감지된 인물에 대해 반투명한 마스크 (= matte) 이미지를 생성합니다. (A request that produces a matte image for a person it finds in the input image.)
  • PixelBufferObservation 타입으로 응답.

 

4. GeneratePersonInstanceMaskRequest

  • 한 이미지 안에서 인물 각각에 대한 마스크를 제공합니다. (A request that produces a mask of individual people it finds in the input image.)
  • InstanceMaskObservation 타입의 결과값.

 

5. DetectDocumentSegmentationRequest

  • 이미지에 포함되어 있는 텍스트를 인식하고, 그 텍스트를 담고 있는 사각형 문서 영역을 감지해줍니다. (A request that detects rectangular regions that contain text in the input image.)
  • DetectedDocumentObservation 타입의 결과값 도출.

이미지 미학 분석 (Image aesthetics analysis)

6. CalculateImageAestheticsScoresRequest [WWDC24]

  • 이미지의 미적 요소 (구도, 노출, 색상 등)를 분석합니다. (A request that analyzes an image for aesthetically pleasing attributes.)
  • ImageAestheticsScoresObservation 타입으로 결과값이 생성됩니다.
    • 타입 안에서 -1에서 1 사이 범위의 Float 값으로 나타나는 overallScore는 미적 품질 (aesthetic quality)을 평가하는 점수입니다. (1에 가까울수록 미적 품질이 높은 이미지. 미적 품질은 구조, 조명, 선명도, 색감과 같은 미학적 요소로 품질을 평가합니다.)
    • 감성적, 미적 목적이 아닌 실용적인 목적의 이미지일 때는 isUtility Bool값이 true로 나타납니다.
      (스크린샷, 영수증 또는 문서, 회의 내용이 포함된 화이트보드, 흐리거나 단순한 정보 전달 목적인 경우 true로 판단한다고 하네요.)

탁월성 분석 (Saliency analysis)

7. GenerateAttentionBasedSaliencyImageRequest

  • 시각적으로 사용자의 주의를 끌만한 부분을 히트맵으로 생성해줍니다. (An object that produces a heat map that identifies the parts of an image most likely to draw attention.)
  • SaliencyImageObservation 타입의 결과가 생성됩니다. 
    • 사각형의 네 꼭짓점 (topLeft, topRight, bottomRight, bottomLeft)을 나타나는 RectangleObservation 객체의 Array인 salientObjects
    •  이미지의 분석 요청으로 생성된 이미지 객체 PixelBufferObservation 타입으로 만들어진 히트맵 heatMap 프로퍼티를 제공합니다.

 

8. GenerateObjectnessBasedSaliencyImageRequest

  • 이미지 안에서 객체일 가능성이 높은 영역에 대한 히트맵을 생성합니다. (A request that generates a heat map that identifies the parts of an image most likely to represent objects.)
  • SaliencyImageObservation 타입의 결과 (위의 GenerateAttentionBasedSaliencyImageRequest 결과내용과 동일!)

객체 추적 (Object tracking)

9. TrackObjectRequest 

  • 다중 이미지나 영상 내에서 특정 객체의 움직임을 추적하는 분석입니다. (An image-analysis request that tracks the movement of a previously identified object across multiple images or video frames.)
  • RectangleObservation 타입의 결과가 도출됩니다.

 

10. TrackRectangleRequest 

  • 다중 이미지나 영상 내에서 사각형 형태 (카드, 책, 문서 등)의 객체를 추적할 수 있습니다. (An image-analysis request that tracks movement of a previously identified rectangular object across multiple images or video frames.)
  • 역시 RectangleObservation 타입의 결과값이 도출됩니다.

얼굴 및 신체 감지 (Face and body detection)

11. DetectFaceRectanglesRequest

  • 이미지 내에 얼굴 위치를 사각형으로 감지합니다. (A request that finds faces within an image.)
  • FaceObservation 객체의 Collection을 결과값으로 반환합니다.

 

12. DetectFaceLandmarksRequest

  • 얼굴의 세부적인 위치, 눈이나 입과 같은 특징의 위치를 좌표값으로 제공합니다. (An image-analysis request that finds facial features like eyes and mouth in an image.)

 

13. DetectFaceCaptureQualityRequest

  • 얼굴 사진의 품질을 0.0~1.0 사이의 float number로 평가해 제공합니다. (A request that produces a floating-point number that represents the capture quality of a face in a photo.)

 

14. DetectHumanRectanglesRequest

  • 이미지에 있는 사람 전체 (머리부터 발끝까지)의 위치를 사각형으로 감지합니다. (A request that finds rectangular regions that contain people in an image.)
  • upperBodyOnly라는 Bool값으로 결과를 생성하기 위해 사람의 상체만 감지하면 되는지 여부를 설정할 수 있습니다. (default값은 true)
  • 결과값은 HumanObservation 타입이고 / 정규화된 사람의 CGRect 타입의 위치boundingBox와, 관찰 결과가 상체 사각형을 나타내는지. 전신 사각형을 나타내는지 나타내는 Bool 타입의 isUpperBodyOnly 프로퍼티를 사용할 수 있습니다.

왼쪽부터 순서대로 Face Detection, Face Landmarks Detection, Face Quiality, Human Rectangle


신체 자세 및 손 자세 감지 (Body and hand pose detection)

15. DetectHumanBodyPoseRequest

  • 인간 신체의 주요 관절 포인트 (머리, 어깨, 무릎과 같은)를 2D로 감지하는 분석입니다. (A request that detects a human body pose.)
  • 결과값은 HumanBodyPostObservation 타입으로 제공됩니다.
    • 감지되는 관절 그룹은 JointGroupName에 정의되어 있습니다. (face, leftArm, leftLeg, rightArm, rightLeg, torso-몸통)
    • 세부적인 관절 포인트는 JointName에 정의되어 있습니다.
  • WWDC24부터는 DetectHumanBodyPoseRequest 하나만으로 신체 주요 관절 포인트와 함께 다음 항목인 손가락 관절의 위치 (HumanHandPoseRequest)를 감지할 수 있게 되었습니다.

 

16. DetectHumanHandPoseRequest

  • 손가락 관절의 위치를 2D로 감지하는 분석입니다. (A request that detects a human hand pose.)
  • HumanHandPoseObservation 타입으로 결과값을 제공합니다.
    • JointsGroupName 타입으로 각 손가락을 인식합니다. (idexFinger, littleFinger, middleFinger, ringFinger, thumb)
    • JointName 타입으로 세부적인 손가락 관절 포인트 21개 (각 손가락당 네 부분씩 + 손목 wrist 부분까지)
    • iOS 18부터는 chirality 속성으로 손의 좌 (left)/우 (right) 정보를 표현합니다. (판별이 어려운 경우 nil 반환)

iOS 18 이후부터는 Human Pose 안에 Hand Pose를 포함해 가져올 수 있습니다.


3D 신체 자세 감지 (3D body pose detection)

17. DetectHumanBodyPose3DRequest

  • 3D 공간 내에서 인간 신체의 관절 포인트를 감지하는 분석입니다. (A request that detects points on human bodies in 3D space, relative to the camera.)

텍스트 감지 (Text detection)

18. RecognizeDocumentsRequest [WWDC25 Update!] 

  • 이미지 내에서 문서의 구조화된 정보 (섹션, 테이블과 같은)를 인식하는데 도움을 줍니다. (An image-analysis request to scan an image of a document and provide information about its structure)

 

19. DetectTextRectanglesRequest

  • 이미지에서 텍스트가 있는 영역을 감지합니다. (An image-analysis request that finds regions of visible text in an image.)
  • 결과값은 TextObservation 타입입니다.
    감지된 텍스트 경계 부분의 박스는 RectangleObservation 타입의 Array인 characterBoxes로 접근해서 위치를 가져올 수 있죠.

 

20. RecognizeTextRequest

  • 이미지에서 텍스트를 인식 (OCR)해 문자열로 추출해줍니다. (An image-analysis request that recognizes text in an image.)
  • RecognizedTextObservation 타입으로 반환이 되고, topCandidates(Int) 메서드로 인식된 텍스트 Array에 대한 상위 후보 (Int번 째)를 요청할 수 있습니다.
  • 이때 요청한 값은 RecognizedText라는 타입으로 제공됩니다.
    인식된 텍스트의 최상위 후보인 string 프로퍼티 / 텍스트 인식 결과에 대한 신뢰도 점수 confidence / 인식된 텍스트 주위의 박스 (RectangleObservation?)를 가져오는 boundingBox(for:)를 활용할 수 있습니다.

바코드 감지 (Barcode detection)

21. DetectBarcodesRequest

  • 이미지의 바코드 (QR 포함)를 인식하고 데이터를 추출할 수 있도록 도와줍니다. (A request that detects barcodes in an image.)
  • 인식된 바코드는 BarcodeSymbology 라는 타입으로 심볼로지를 확인할 수 있습니다.

궤적, 윤곽 및 수평선 감지 (Trajectory, contour, and horizon detection)

22. DetectTrajectoriesRequest

  • 포물선을 그리며 이동하는 물체의 궤적을 감지합니다. (A request that detects the trajectories of shapes moving along a parabolic path.)
  • 결과값은 TrajectoryObservation 입니다.
    주로 연속된 프레임을 분석하기 때문에 Array로 제공되고 / 각 궤적마다, 궤적에서 감지된 중심점 detectedPoints, 포물선 근사에 사용된 경로점 projectedPoints, 포물선 방정식의 개수 equationCoefficients, 평균 이동 반경 movingAverageRadius 값 등을 받을 수 있습니다.

 

23. DetectContoursRequest

  • 이미지의 경계선을 벡터 형태로 추출해줍니다. (A request that detects the contours of the edges of an image.)
  • 결과는 ContoursObservation 타입입니다.
  • 이미지에서 감지된 윤곽은 Contour라는 객체의 형태로 표현되고, 이 객체를 얻기 위해 contourAtIndex(Int) 또는 contourAtIndexPath(IndexPath) 메서드를 활용할 수 있습니다.
  • 해당 API 요청 시에는 윤곽을 감지할 때 민감도가 표현되는 대비양 contrastAdjustment, 대비를 위해 피벗으로 사용할 contrastPivot, 감지를 돕기 위해 밝은 배경에 어두운 객체를 감지하는지 여부를 표현할 수 있는 detectsDarkOnLight 프로퍼티 등을 활용할 수 있습니다.

 

24. DetectHorizonRequest

  • 이미지의 수평선 기울기를 추적해주는 분석입니다. (An image-analysis request that determines the horizon angle in an image)
  • HorizonObservation 타입의 결과는 기울기 angle, 결과 이미지의 기울기를 보정하기 위한 2D 변환 메서드 transform(for:) 등으로 활용할 수 있습니다.

동물 감지 (Animal detection)

25. DetectAnimalBodyPoseRequest

  • 동물의 포즈 (관절 위치)를 감지합니다. (A request that detects an animal body pose)

 

26. RecognizeAnimalsRequest

  • 이미지에서 동물의 종을 분류합니다. (A request that recognizes animals in an image)

광학 흐름 및 사각형 감지 (Optical flow and rectangle detection)

27. TrackOpticalFlowRequest

  • 이미지 간 픽셀 수준의 움직임 (방향, 속도)을 감지할 수 있도록 해주는 분석입니다. (A request that determines the direction change of vectors for each pixel from a previous to current image)

 

28. DetectRectanglesRequest

  • 이미지 내에서 사각형을 감지하는 분석입니다. (An image-analysis request that finds projected rectangular regions in an image)

이미지 정렬 (Image alignment)

29. TrackTranslationalImageRegistrationRequest

  • 두 이미지 간의 단순한 수평 또는 수직 방향의 이동(Translation)만 고려하여 정렬하는 요청입니다. (An image-analysis request that you track over time to determine the affine transform necessary to align the content of two images)

 

30. TrackHomographicImageRegistrationRequest

  • 투시 변환 (Perspective Warp, Homography)을 포함한 복잡한 이미지 정렬을 수행하는 요청입니다. (An image-analysis request that you track over time to determine the perspective warp matrix necessary to align the content of two images)

이미지 기능 인쇄 및 배경 제거 (Image feature print and background removal)

31. GenerateImageFeaturePrintRequest

  • 이미지의 고유 특징 벡터를 생성합니다. (An image-based request to generate feature prints from an image)

 

32. GenerateForegroundInstanceMaskRequest

  • 눈에 띄는 객체를 배경과 분리하기 위한 마스크를 생성합니다. (A request that generates an instance mask of noticeable objects to separate from the background)

머신러닝 이미지 분석 (Machine learning image analysis)

33. CoreMLRequest