https://github.com/t8rin/imagetextreader
📸 ImageTextReader is a Library for performing OCR in fast and convenient way
https://github.com/t8rin/imagetextreader
android kotlin library ocr ocr-recognition tesseract tesseract-ocr
Last synced: 7 months ago
JSON representation
📸 ImageTextReader is a Library for performing OCR in fast and convenient way
- Host: GitHub
- URL: https://github.com/t8rin/imagetextreader
- Owner: T8RIN
- License: apache-2.0
- Created: 2024-05-15T21:53:51.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-05-16T20:04:10.000Z (over 1 year ago)
- Last Synced: 2024-05-17T10:56:05.215Z (over 1 year ago)
- Topics: android, kotlin, library, ocr, ocr-recognition, tesseract, tesseract-ocr
- Language: Kotlin
- Homepage:
- Size: 114 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
ImageTextReader
📸 ImageTextReader is a Library for performing OCR in fast and convenient way## Features
- 120+ languages
- 3 Type of data: Fast, Standard, Best
- Segmentation Mode Selection
- Multiple languages at the same time## Usage
### 1. Add dependencies
#### Kotlin (kts)
```kotlin
repositories {
maven { setUrl("https://jitpack.io") } // Add jitpack
}
dependencies {
implementation("com.github.T8RIN:ImageTextReader:LATEST_VERSION") // Replace "LATEST_VERSION" with preferrend version tag
}
```#### Groovy
```groovy
repositories {
maven { url 'https://jitpack.io' } // Add jitpack
}
dependencies {
implementation 'com.github.T8RIN:ImageTextReader:LATEST_VERSION' // Replace "LATEST_VERSION" with preferrend version tag
}
```### 2. Get `ImageTextReader` instance
```kotlin
// Use injection through dagger
@Inject
lateinit var imageTextReader: ImageTextReader// Or inject in ViewModel
@HiltViewModel
class ExampleViewModel @Inject constructor(
private val imageTextReader: ImageTextReader
): ViewModel()// Or obtain new instance passing application context
val imageTextReader: ImageTextReader = ImageTextReader(context)/* When you have ImageTextReader instance use it as shown below */
// First get available languages list
val recognitionType: RecognitionType = RecognitionType.Standard // Also available Best and Fast models
val languages: List = imageTextReader.getLanguages(recognitionType)// Or get OCRLanguage by code, for example `en`
val language: OCRLanguage = imageTextReader.getLanguageForCode("en")// Select needed languages
val languageCode = selectedLanguages.joinToString("+") { it.code } // selectedLanguages is your needed OCRLanguage instances// Or with single language
val languageCode = language.code// Set some parameters
val segmentationMode: SegmentationMode = SegmentationMode.PSM_AUTO_OSD
val ocrEngineMode: OcrEngineMode = OcrEngineMode.DEFAULTimageTextReader.getTextFromImage(
type = recognitionType,
languageCode = languageCode,
segmentationMode = segmentationMode,
image = bitmap,
ocrEngineMode = ocrEngineMode,
onProgress = { progress ->
// Get recognition progress in percents
}
).also { result ->
when (result) {
is TextRecognitionResult.Error -> {
val throeable: Throwable = result.throwable
}is TextRecognitionResult.NoData -> {
val downloadData: List = result.data
}is TextRecognitionResult.Success -> {
val text: String = result.data
}
}
}// When you have downloadData you can download them as shown below
val isDownloadSuccessfully: Boolean = imageTextReader.downloadTrainingData(
type = recognitionType,
languageCode = downloadData.joinToString(separator = "+") { it.languageCode },
onProgress = { percentage, totalContentSize ->
// Get current download progress and total size of model
}
)// Also you can check if some language model exists for selected recognition type
fun isLanguageDataExists(
type: RecognitionType,
languageCode: String
): Boolean// Or delete model that stored in memory
suspend fun deleteLanguage(
language: OCRLanguage,
types: List
)```
## Find this repository useful? :heart:
Support it by joining __[stargazers](https://github.com/T8RIN/ImageTextReader/stargazers)__ for this repository. :star:
And __[follow](https://github.com/T8RIN)__ me for my next creations! 🤩## License
```xml
Designed and developed by 2024 T8RINLicensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```