This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pods for TextDetect | |
pod 'Firebase/Core' , '~> 5.2.0' | |
pod 'Firebase/MLVision', '~> 5.2.0' | |
pod 'Firebase/MLVisionTextModel', '~> 5.2.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let languages = ["Select Language", "Hindi", "French", "Italian", "German", "Japanese"] | |
let languageCodes = ["hi", "hi", "fr", "it", "de", "ja"] | |
var targetCode = "hi" | |
// MARK :- UIPickerViewDelegate | |
extension ViewController: UIPickerViewDataSource, UIPickerViewDelegate { | |
func numberOfComponents(in pickerView: UIPickerView) -> Int { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IBAction func languageSelectorTapped(_ sender: Any) { | |
if pickerVisible { | |
languagePickerHeightConstraint.constant = 0 | |
pickerVisible = false | |
translateText(detectedText: self.detectedText.text ?? "") | |
} else { | |
languagePickerHeightConstraint.constant = 150 | |
pickerVisible = true | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func translateText(detectedText: String) { | |
guard !detectedText.isEmpty else { | |
return | |
} | |
let task = try? GoogleTranslate.sharedInstance.translateTextTask(text: detectedText, targetLanguage: self.targetCode, completionHandler: { (translatedText: String?, error: Error?) in | |
debugPrint(error?.localizedDescription) | |
DispatchQueue.main.async { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Firebase | |
class ViewController: UIViewController { | |
lazy var vision = Vision.vision() | |
var textDetector: VisionTextDetector? | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func detectText (image: UIImage) { | |
textDetector = vision.textDetector() | |
let visionImage = VisionImage(image: image) | |
textDetector?.detect(in: visionImage) { (features, error) in | |
guard error == nil, let features = features, !features.isEmpty else { | |
return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: - AVCaptureVideoDataOutputSampleBufferDelegate | |
/* This delegate is fired periodically every time a new video frame is written. | |
It is called on the dispatch queue specified while setting up the capture session. | |
*/ | |
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { | |
/* Initialise CVPixelBuffer from sample buffer | |
CVPixelBuffer is the input type we will feed our coremlmodel . | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ViewController: UIViewController, AVCaptureVideoDataOutputSampleBufferDelegate { | |
... | |
... | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func configureCamera() { | |
//Start capture session | |
let captureSession = AVCaptureSession() | |
captureSession.sessionPreset = .photo | |
captureSession.startRunning() | |
// Add input for capture | |
guard let captureDevice = AVCaptureDevice.default(for: .video) else { return } | |
guard let captureInput = try? AVCaptureDeviceInput(device: captureDevice) else { return } |
NewerOlder