Created
January 25, 2021 06:12
-
-
Save erdalkaymak/9a9fac573a5adc2edfaa9bdfc31a5330 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| private fun performTextRecognitionOnDevice(bitmap: Bitmap){ | |
| var myText:String?=null | |
| val setting = MLLocalTextSetting.Factory() | |
| .setOCRMode(MLLocalTextSetting.OCR_DETECT_MODE) | |
| .create() | |
| val analyzer = MLAnalyzerFactory.getInstance().getLocalTextAnalyzer(setting) | |
| val frame = MLFrame.fromBitmap(bitmap) | |
| val task: Task<MLText> = analyzer.asyncAnalyseFrame(frame) | |
| task.addOnSuccessListener { | |
| txt_translate_result.visibility= View.VISIBLE | |
| txt_to.visibility= View.VISIBLE | |
| txt_translation.visibility= View.VISIBLE | |
| toSpinner.visibility= View.VISIBLE | |
| selected_img.visibility= View.VISIBLE | |
| text_recognition_device_text.visibility= View.VISIBLE | |
| text_recognition_device_text.setText(it.stringValue) | |
| detectAndTranslateLanguage(it.stringValue, txt_translation,languageCode.toString(),applicationContext) | |
| myText=SharedPreferencesUtil.getInstance(applicationContext)!!.getStringValue("detectedLanguage") | |
| txt_detect_result.text="Detected Result " + "("+getLanguage(myText!!)+")" | |
| txt_detect_result.visibility= View.VISIBLE | |
| detectedText=it.stringValue | |
| isEntered=true | |
| SharedPreferencesUtil.getInstance(applicationContext)!!.deleteValue("detectedLanguage") | |
| }.addOnFailureListener { | |
| Toast.makeText( | |
| this, | |
| "Text recognition failed, error message ->${it.message}", | |
| Toast.LENGTH_SHORT | |
| ).show() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment