Skip to main content

Usage

Setup

val ocr = YesidOCRCamera
ocr.userLicense = stringResource(id = "LicenseKey")
val ocrConfigurationBuilder by mutableStateOf(OCRConfigurationBuilder)

//Inside a composable function just do the following
@Composable
fun MyComposable() {
ocr.OCRCamera(
configurationBuilder = ocrConfigurationBuilder,
onResults = {
Log.e("Results", "${it}")
}
)
}

Using Fragments in Kotlin or Java

In your activity_main.xml file add the following:

  <androidx.fragment.app.FragmentContainerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/main_container"
/>
//Create a CardDetectionFragment and call the OCR Camera
class CardDetectionFragment : Fragment() {
@RequiresApi(Build.VERSION_CODES.O)
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
val view = ComposeView(requireContext())
view.apply {
setContent {
Column(
modifier = Modifier.fillMaxSize(),
) {
MyComposable()
}
}
}
return view
}

@Composable
fun MyComposable() {
val ocr = YesidOCRCamera
ocr.userLicense = stringResource(id = "LicenseKey")
val ocrConfigurationBuilder by mutableStateOf(OCRConfigurationBuilder)

// create the object
ocr.OCRCamera(
configurationBuilder = ocrConfigurationBuilder,
onResults = {
Log.e("Results", "${it}")
}
)
}
}

On your activity then call the CardDetectionFragment

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
supportFragmentManager.beginTransaction()
.replace(R.id.main_container, CardDetectionFragment()).commit()
}
}