suripappu Rengan
suripappu Rengan

Reputation: 61

how to convert image to text using iOS swift?

how to convert image to text using iOS swift ?

Step 01: Take a photo using iOS camera . (Done by using UIImagePickerController in iOS swift)

Step 02: I got image .

Step 03 : I have to convert these image (UIImage) to text format .

using iOS swift .

I have referred many links as already we have VNDetectTextRectanglesRequest for identifying character box .

but my purpose is how we convert from image to text . Not as an rectangular boxes using iOS swift

Upvotes: 3

Views: 19837

Answers (4)

Selva
Selva

Reputation: 60

Using CoreML's VNDetectTextRectanglesRequest, you only able to find regions of visible text in an image. And, thats not enough to get text out from an image with swift.

First step is to crop the images, You will need to crop the images for each image in VNTextObservation. Like

    for textObservation in textObservations {
        guard let rects = textObservation.characterBoxes else {
            continue
        }
        var xMin = CGFloat.greatestFiniteMagnitude
        var xMax: CGFloat = 0
        var yMin = CGFloat.greatestFiniteMagnitude
        var yMax: CGFloat = 0
        for rect in rects {

            xMin = min(xMin, rect.bottomLeft.x)
            xMax = max(xMax, rect.bottomRight.x)
            yMin = min(yMin, rect.bottomRight.y)
            yMax = max(yMax, rect.topRight.y)
        }
       let imageRect = CGRect(x: xMin * size.width, y: yMin * size.height, width: (xMax - xMin) * size.width, height: (yMax - yMin) * size.height)

Second step is to send images to image processing tools like Opencv etc,.there are some online tutorials about how to integrate with iOS and you can use objective-c header if you want to use it with swift. https://medium.com/pharos-production/using-opencv-in-a-swift-project-679868e1b798

Once you got processed image, Third step is As mentioned by Nick,
you then use tesseract or ABBYY SDK's.

Tesseract is free to use and you can find iOS framework for tesseract 3.03-rc1 here. The most important thing you need to aware about OCR tools is language. What language you try to convert ? what language the detected image has ? Mostly you got trained data for multiple languages in the tesseract repository. In Summary, the work flow will be ,

Image Capture -> Image Process -> OCR process

Upvotes: 2

Nick
Nick

Reputation: 875

If you need to recognise text from image then you can refer this:

1) Tesseract OCR : https://github.com/cconstable/OCR-iOS-Example

2) ABBYY : http://abbyy.com/mobileocr/iphone

3) Google Cloud Vision : https://cloud.google.com/vision/

Tesseract OCR was more accurate depending on the image resolution, fonts, text color etc.

Upvotes: 0

Ayman Ferki
Ayman Ferki

Reputation: 313

I think you talk about extracting text from images A process called cOCR "Optical character recognition"

Read : https://en.wikipedia.org/wiki/Optical_character_recognition IOS has no builtIn OCR SDK/library

i highly advice that you check Tesseract, an open-source OCR engine maintained by Google . https://github.com/tesseract-ocr/tesseract

also you can found a complete swift4 article here

https://www.raywenderlich.com/163445/tesseract-ocr-tutorial-ios

also remember to capture high quality picture before OCR process .

Upvotes: 0

Swati Gautam
Swati Gautam

Reputation: 191

If you need to convert the image to text for OCR then you can use the following links:-

There is no in-built libraries for OCR but you can use the following links

1) Open Source OCR - Tesseract http://code.google.com/p/tesseract-ocr/ - completely free, but less accurate.

This link will show how to run in iPhone: https://github.com/nolanbrown/Tesseract-iPhone-Demo

2) Commercial OCR - http://abbyy.com/mobileocr/iphone - highly accurate, customer support, etc. but it costs money.

Upvotes: 0

Related Questions