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
using UnityEngine; | |
public class CharacterStateMachine : StateMachineBehaviour | |
{ | |
public static CharacterAnimationState characterAnimationState; | |
public static BaseCharacter baseCharacter; | |
public static void setBaseCharacter<T>(T character) where T : BaseCharacter | |
{ |
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
// TextRecognitionViewModel | |
fun analyzeBitmap(bitmap: Bitmap) { | |
textRecognizer.analyzeBitmap(bitmap) { | |
Timber.d("stringValue is ${it.stringValue}") | |
if (it.stringValue.isEmpty()) { | |
outputLiveData.value = "No text recognized !!" | |
Timber.e("No text recognized !!") | |
} |
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
// TextRecognitionViewModel | |
fun analyzeStream() { | |
if (isCameraStarted) | |
textRecognizer.analyzeStream { | |
it.forEach { _, value -> | |
Timber.d("stringValue is ${value?.stringValue}") | |
outputLiveData.postValue(value?.stringValue) | |
value?.contents?.forEachIndexed { index, element -> | |
Timber.d("[$index] is ${element.stringValue}") |
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
var resultAction: ((SparseArray<MLText.Block?>) -> Unit)? = null | |
override fun transactResult(results: MLAnalyzer.Result<MLText.Block?>) { | |
val items = results.analyseList | |
// Determine detection result processing as required. Note that only the detection results are processed. | |
// Other detection-related APIs provided by ML Kit cannot be called. | |
resultAction?.invoke(items) | |
resultAction = null | |
} |
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
// TextRecognitionViewModel.kt | |
fun initializeStreamAnalyzer(context: Context) { | |
textRecognizer.initializeStreamAnalyzer(context) | |
} | |
// TextRecognizer.kt | |
fun initializeStreamAnalyzer(context: Context) { | |
initializeDeviceStreamAnalyzer(context) | |
} |
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
enum class TextLanguage(val languageCode: String) { | |
ENGLISH("en"), | |
CHINESE( "cn"), | |
TURKISH("tr") | |
} |
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
// TextRecognitionViewModel.kt | |
fun initializeTextAnalyzer(isNetworkConnected: Boolean) { | |
textRecognizer.initializeTextAnalyzer(isNetworkConnected, TextLanguage.TURKISH) | |
} | |
// TextRecognizer.kt | |
fun initializeTextAnalyzer(isNetworkConnected: Boolean = false, textLanguage: TextLanguage) { | |
if (isNetworkConnected) | |
initializeCloudTextAnalyzer(listOf(textLanguage.languageCode)) | |
else |
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
override fun onResume() { | |
super.onResume() | |
openCameraStream(lensEngine ?: return) | |
} | |
override fun onPause() { | |
super.onPause() | |
closeCameraStream() | |
} |
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
private fun initializeLensEngine() { | |
lensEngine = LensEngine.Creator(activity, analyzer) | |
.setLensType(LensEngine.FRONT_LENS) | |
.applyDisplayDimension(WIDTH, HEIGHT) | |
.applyFps(FPS) | |
.enableAutomaticFocus(true) | |
.create() | |
} |
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
private fun initializeAnalyzer() { | |
val setting = MLImageSegmentationSetting.Factory() // Set whether to support fine segmentation. The value true indicates fine segmentation, and the value false indicates fast segmentation. | |
.setExact(false) | |
.setAnalyzerType(MLImageSegmentationSetting.BODY_SEG) | |
.setScene(MLImageSegmentationScene.FOREGROUND_ONLY) | |
.create() | |
analyzer = MLAnalyzerFactory.getInstance().getImageSegmentationAnalyzer(setting) | |
analyzer?.setTransactor(ImageSegmentAnalyzerTransactor(binding?.graphic ?: return)) | |
} |
NewerOlder