-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2c8de6
commit 8c61e0f
Showing
12 changed files
with
363 additions
and
370 deletions.
There are no files selected for viewing
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
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
93 changes: 0 additions & 93 deletions
93
sample/src/main/java/cz/adaptech/tesseract4android/sample/Assets.java
This file was deleted.
Oops, something went wrong.
88 changes: 88 additions & 0 deletions
88
sample/src/main/java/cz/adaptech/tesseract4android/sample/Assets.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package cz.adaptech.tesseract4android.sample | ||
|
||
import android.content.Context | ||
import android.content.res.AssetManager | ||
import android.graphics.Bitmap | ||
import android.graphics.BitmapFactory | ||
import java.io.File | ||
import java.io.FileOutputStream | ||
import java.io.IOException | ||
|
||
object Assets { | ||
/** | ||
* Returns locally accessible directory where our assets are extracted. | ||
*/ | ||
fun getLocalDir(context: Context): File { | ||
return context.filesDir | ||
} | ||
|
||
/** | ||
* Returns locally accessible directory path which contains the "tessdata" subdirectory | ||
* with *.traineddata files. | ||
*/ | ||
@JvmStatic | ||
fun getTessDataPath(context: Context): String { | ||
return getLocalDir(context).absolutePath | ||
} | ||
|
||
@JvmStatic | ||
fun getImageFile(context: Context): File { | ||
return File(getLocalDir(context), Config.IMAGE_NAME) | ||
} | ||
|
||
@JvmStatic | ||
fun getImageBitmap(context: Context): Bitmap? { | ||
return BitmapFactory.decodeFile(getImageFile(context).absolutePath) | ||
} | ||
|
||
@JvmStatic | ||
fun extractAssets(context: Context) { | ||
val am = context.assets | ||
|
||
val localDir = getLocalDir(context) | ||
if (!localDir.exists() && !localDir.mkdir()) { | ||
throw RuntimeException("Can't create directory $localDir") | ||
} | ||
|
||
val tessDir = File(getTessDataPath(context), "tessdata") | ||
if (!tessDir.exists() && !tessDir.mkdir()) { | ||
throw RuntimeException("Can't create directory $tessDir") | ||
} | ||
|
||
// Extract all assets to our local directory. | ||
// All *.traineddata into "tessdata" subdirectory, other files into root. | ||
try { | ||
for (assetName in am.list("")!!) { | ||
val targetFile = if (assetName.endsWith(".traineddata")) { | ||
File(tessDir, assetName) | ||
} else { | ||
File(localDir, assetName) | ||
} | ||
if (!targetFile.exists()) { | ||
copyFile(am, assetName, targetFile) | ||
} | ||
} | ||
} catch (e: IOException) { | ||
e.printStackTrace() | ||
} | ||
} | ||
|
||
private fun copyFile( | ||
am: AssetManager, assetName: String, | ||
outFile: File | ||
) { | ||
try { | ||
am.open(assetName).use { `in` -> | ||
FileOutputStream(outFile).use { out -> | ||
val buffer = ByteArray(1024) | ||
var read: Int | ||
while ((`in`.read(buffer).also { read = it }) != -1) { | ||
out.write(buffer, 0, read) | ||
} | ||
} | ||
} | ||
} catch (e: IOException) { | ||
e.printStackTrace() | ||
} | ||
} | ||
} |
12 changes: 0 additions & 12 deletions
12
sample/src/main/java/cz/adaptech/tesseract4android/sample/Config.java
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
sample/src/main/java/cz/adaptech/tesseract4android/sample/Config.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package cz.adaptech.tesseract4android.sample | ||
|
||
import com.googlecode.tesseract.android.TessBaseAPI | ||
|
||
object Config { | ||
const val TESS_ENGINE: Int = TessBaseAPI.OEM_LSTM_ONLY | ||
|
||
const val TESS_LANG: String = "eng" | ||
|
||
const val IMAGE_NAME: String = "sample.jpg" | ||
} |
21 changes: 0 additions & 21 deletions
21
sample/src/main/java/cz/adaptech/tesseract4android/sample/MainActivity.java
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
sample/src/main/java/cz/adaptech/tesseract4android/sample/MainActivity.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package cz.adaptech.tesseract4android.sample | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import cz.adaptech.tesseract4android.sample.ui.main.MainFragment | ||
|
||
class MainActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
if (savedInstanceState == null) { | ||
supportFragmentManager.beginTransaction() | ||
.replace(R.id.container, MainFragment.newInstance()) | ||
.commitNow() | ||
} | ||
} | ||
} |
77 changes: 0 additions & 77 deletions
77
sample/src/main/java/cz/adaptech/tesseract4android/sample/ui/main/MainFragment.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.