# Vision Framework ile Goruntu Isleme Rehberi
Goruntu isleme, mobil uygulamalarin en etkileyici yeteneklerinden biridir. Apple'in Vision framework'u, yuz tespiti, metin tanima (OCR), barkod okuma, goruntu siniflandirma ve nesne takibi gibi guclu bilgisayarli goru ozelliklerini iOS uygulamalarina entegre etmenizi saglar. Tum islemler cihaz uzerinde, Neural Engine destegi ile calisir.
"Bir resim bin kelimeye bedeldir — ama Vision framework ile o bin kelimeyi de okuyabilirsiniz." — Computer Vision Pratikleri
Icindekiler
- Vision Framework Nedir?
- Request-Handler Mimarisi
- Yuz Tespiti ve Analizi
- Metin Tanima (OCR)
- Barkod ve QR Kod Okuma
- Goruntu Siniflandirma
- Nesne Takibi
- Vucut ve El Pozu Tespiti
- Performance Optimizasyonu
- Okuyucu Odulu
- Sonuc
1. Vision Framework Nedir?
Vision, iOS 11+ ile kullanilabilen Apple'in bilgisayarli goru framework'udur. Core ML ile entegre calisarak custom model'leri de destekler.
Vision Yetenekleri
Ozellik | iOS Versiyonu | Neural Engine | Dogruluk |
|---|---|---|---|
Yuz Tespiti | iOS 11+ | Evet | %99+ |
Yuz Landmarklari | iOS 11+ | Evet | %97+ |
Metin Tanima (OCR) | iOS 13+ | Evet | %95+ |
Barkod/QR Okuma | iOS 11+ | Hayir | %99+ |
Goruntu Siniflandirma | iOS 13+ | Evet | Model bagimli |
Nesne Takibi | iOS 11+ | Evet | %95+ |
Vucut Pozu | iOS 14+ | Evet | %93+ |
El Pozu | iOS 14+ | Evet | %92+ |
Belge Tespiti | iOS 15+ | Evet | %98+ |
Hayvan Tespiti | iOS 13+ | Evet | %90+ |
2. Request-Handler Mimarisi
Vision, request-handler pattern'i kullanir. Her islem bir VNRequest olarak tanimlanir ve VNImageRequestHandler ile calistirilir.
swift
1import Vision2import UIKit3 4// Temel Vision pipeline5class VisionProcessor {6 7 func processImage(_ image: UIImage, requests: [VNRequest]) throws {8 guard let cgImage = image.cgImage else {9 throw VisionError.invalidImage10 }11 12 // Handler olustur13 let handler = VNImageRequestHandler(14 cgImage: cgImage,15 orientation: .up,16 options: [:]17 )18 19 // Request'leri calistir20 try handler.perform(requests)21 }22 23 // Video akisi icin sequence handler24 func processVideoFrame(25 _ pixelBuffer: CVPixelBuffer,26 requests: [VNRequest]27 ) throws {28 let handler = VNImageRequestHandler(29 cvPixelBuffer: pixelBuffer,30 orientation: .up,31 options: [:]32 )33 34 try handler.perform(requests)35 }36}37 38enum VisionError: Error {39 case invalidImage40 case processingFailed41}Request Turleri
Request'ler iki ana kategoriye ayrilir:
- Image Analysis: Tek bir goruntu uzerinde analiz (VNImageRequestHandler)
- Sequence Analysis: Video frame'leri uzerinde takip (VNSequenceRequestHandler)
3. Yuz Tespiti ve Analizi
swift
1import Vision2 3class FaceDetector {4 5 func detectFaces(in image: CGImage) async throws -> [FaceResult] {6 let request = VNDetectFaceRectanglesRequest()7 request.revision = VNDetectFaceRectanglesRequestRevision38 9 let handler = VNImageRequestHandler(cgImage: image)10 try handler.perform([request])11 12 guard let observations = request.results else {13 return []14 }15 16 return observations.map { observation in17 FaceResult(18 boundingBox: observation.boundingBox,19 confidence: observation.confidence,20 roll: observation.roll?.doubleValue,21 yaw: observation.yaw?.doubleValue,22 pitch: observation.pitch?.doubleValue23 )24 }25 }26 27 func detectFaceLandmarks(in image: CGImage) async throws -> [VNFaceObservation] {28 let request = VNDetectFaceLandmarksRequest()29 request.revision = VNDetectFaceLandmarksRequestRevision330 31 let handler = VNImageRequestHandler(cgImage: image)32 try handler.perform([request])33 34 return request.results ?? []35 }36}37 38struct FaceResult {39 let boundingBox: CGRect40 let confidence: Float41 let roll: Double?42 let yaw: Double?43 let pitch: Double?44}Yuz tespiti ile goz, burun, agiz gibi 76 landmark noktasini elde edebilirsiniz. Bu noktalar filtre uygulama, emoji yerlestirme veya dikkat tespiti gibi islemler icin kullanilir.
4. Metin Tanima (OCR)
VNRecognizeTextRequest, goruntulerden metin cikarma icin kullanilir. iOS 16+ ile revision 3 son derece yuksek dogruluk saglar.
swift
1import Vision2 3class TextRecognizer {4 5 func recognizeText(6 in image: CGImage,7 languages: [String] = ["tr", "en"],8 level: VNRequestTextRecognitionLevel = .accurate9 ) async throws -> [RecognizedText] {10 let request = VNRecognizeTextRequest()11 request.recognitionLevel = level12 request.recognitionLanguages = languages13 request.usesLanguageCorrection = true14 15 let handler = VNImageRequestHandler(cgImage: image)16 try handler.perform([request])17 18 guard let observations = request.results else {19 return []20 }21 22 return observations.compactMap { observation in23 guard let candidate = observation.topCandidates(1).first else {24 return nil25 }26 27 return RecognizedText(28 text: candidate.string,29 confidence: candidate.confidence,30 boundingBox: observation.boundingBox31 )32 }33 }34}35 36struct RecognizedText {37 let text: String38 let confidence: Float39 let boundingBox: CGRect40}OCR Performans Karsilastirmasi
Recognition Level | Hiz | Dogruluk | Kullanim Alani |
|---|---|---|---|
.fast | 10-30ms | %85-90 | Real-time kamera |
.accurate | 50-200ms | %95-99 | Belge tarama |
Easter Egg
Gizli bir bilgi buldun!
Bu bölümde gizli bir bilgi var. Keşfetmek ister misin?
5. Barkod ve QR Kod Okuma
swift
1import Vision2 3func detectBarcodes(in image: CGImage) throws -> [VNBarcodeObservation] {4 let request = VNDetectBarcodesRequest()5 request.symbologies = [6 .qr, .ean13, .ean8, .code128, .code39, .upce,7 .pdf417, .aztec, .dataMatrix8 ]9 10 let handler = VNImageRequestHandler(cgImage: image)11 try handler.perform([request])12 13 return request.results ?? []14}6. Goruntu Siniflandirma
Vision framework, Core ML modelleri ile entegre calisarak custom goruntu siniflandirma yapar. VNCoreMLRequest ile kendi egittiginiz veya hazir bir Core ML modelini Vision pipeline'ina dahil edebilirsiniz.
swift
1import Vision2import CoreML3 4class ImageClassifier {5 6 private lazy var classificationRequest: VNCoreMLRequest? = {7 guard let model = try? VNCoreMLModel(8 for: MobileNetV2(configuration: .init()).model9 ) else { return nil }10 11 let request = VNCoreMLRequest(model: model) { request, error in12 guard let results = request.results as? [VNClassificationObservation] else { return }13 14 let topResults = results.prefix(3)15 for result in topResults {16 print("\(result.identifier): %\(Int(result.confidence * 100))")17 }18 }19 request.imageCropAndScaleOption = .centerCrop20 return request21 }()22 23 func classify(image: CGImage) throws {24 guard let request = classificationRequest else { return }25 let handler = VNImageRequestHandler(cgImage: image, options: [:])26 try handler.perform([request])27 }28}Model secimi uygulamanizin ihtiyacina gore degisir. MobileNetV2 hiz ve boyut acisindan dengelidir; daha yuksek dogruluk icin ResNet veya EfficientNet modellerini tercih edebilirsiniz.
7. Nesne Takibi (Object Tracking)
Video frame'lerinde bir nesneyi takip etmek icin VNTrackObjectRequest kullanilir. Oyun, spor analizi ve AR uygulamalarinda yaygin kullanilir.
8. Vucut ve El Pozu Tespiti
iOS 14+ ile vucut ve el pozu tespiti mumkundur. Fitness, isaret dili tanima ve gesture control icin idealdir.
9. Performance Optimizasyonu
Strateji | Etki | Uygulama |
|---|---|---|
Region of Interest | 2-5x hizlanma | request.regionOfInterest ayarla |
Revision secimi | Dogruluk/hiz dengesi | En son revision kullan |
Pixel buffer reuse | Bellek tasarrufu | CVPixelBufferPool kullan |
Batch requests | Overhead azaltma | Tek handler'da birden fazla request |
Background thread | UI donmesi onleme | DispatchQueue.global kullan |
ALTIN İPUCU
Bu yazının en değerli bilgisi
Bu ipucu, yazının en önemli çıkarımını içeriyor.
Okuyucu Ödülü
Tebrikler! Bu yazıyı sonuna kadar okuduğun için sana özel bir hediyem var:
Sonuç ve Öneriler
Vision framework, iOS uygulamalarina gorsel zeka katmanin en etkili ve kapsamli yoludur. Yuz tespiti, OCR, barkod okuma, goruntu siniflandirma ve nesne takibi gibi genis bir ozellik yelpazesini tek bir framework altinda sunar. Request-handler mimarisi sayesinde farkli islemleri kolayca birlestirebilir, zincirleme pipeline'lar olusturabilir ve karmasik goruntu analizi senaryolarini yonetebilirsiniz.
Vision ile calisirken performans optimizasyonuna ozellikle dikkat edin. Goruntu isleme islemleri CPU ve GPU yogun olabilir, bu nedenle her zaman background thread kullanin ve ana thread'i bloke etmeyin. Region of interest (ROI) ayarlarini dogru yaparak yalnizca ilgili alani analiz edin — bu hem hizi arttirir hem de dogr ulugu iyilestirir. Kamera akisindan gelen kareleri islerken frame rate'i ihtiyaciniza gore sinirlayin; her kareyi analiz etmek yerine belirli araliklarla islem yapmak pil omrunu onemli olcude uzatir.
Production uygulamalarinda Vision request'lerinin revision parametresini dogru secmek kritiktir. Her iOS surumu yeni revision'lar getirir ve yeni revision'lar genellikle daha yuksek dogruluk sunar. Ancak geriye donuk uyumluluk icin minimum desteklenen iOS surumunuzu goz onunde bulundurun. Ayrica Vision sonuclarini Core ML modelleriyle birlestirerek daha gelismis senaryolar olusturabilirsiniz — ornegin once Vision ile yuz tespiti yapin, sonra Core ML ile yuz ifadesi analizi gerceklestirin. Bu hibrit yaklasim, uygulamaniza rakiplerinden onemli olcude ayrisan gorsel zeka yetenekleri kazandirir.

