Skip to content

Instantly share code, notes, and snippets.

View Lavanyagaur22's full-sized avatar
🚩

Lavanya gaur Lavanyagaur22

🚩
View GitHub Profile
// Get the system service for the camera manager
val manager = getSystemService(Context.CAMERA_SERVICE) as CameraManager
// Gets the first camera id
var cameraId = manager.getCameraIdList().get(0)
// Determine the rotation on the FritzVisionImage from the camera orientaion and the device rotation.
// "this" refers to the calling Context (Application, Activity, etc)
var imageRotationFromCamera = FritzVisionOrientation.getImageRotationFromCamera(this, cameraId)
val mediaImage = image?.image
val imageRotation = ImageRotation.getFromValue(rotationDegrees)
val visionImage = FritzVisionImage.fromMediaImage(mediaImage, imageRotation)
val labelResult = predictor?.predict(visionImage)
runOnUiThread {
labelResult?.resultString?.let {
val sname = it.split(":")
Log.e(TAG, it)
var predictor: FritzVisionLabelPredictor? = null
val managedModel = ImageLabelManagedModelFast()
FritzVision.ImageLabeling.loadPredictor(
managedModel,
object : PredictorStatusListener<FritzVisionLabelPredictor> {
override fun onPredictorReady(p0: FritzVisionLabelPredictor?) {
Log.d(TAG, "Image Labeling predictor is ready")
predictor = p0
}
class ImageProcessor : ImageAnalysis.Analyzer {
var predictor: FritzVisionLabelPredictor? = null
val TAG = javaClass.simpleName
override fun analyze(image: ImageProxy?, rotationDegrees: Int) {
//Handle all the ML logic here
val mediaImage = image?.image
val imageRotation = ImageRotation.getFromValue(rotationDegrees)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
/*In the MainActivity class, initialize Fritz SDK.
*/
Fritz.configure(this, API_KEY)
/*Instead of calling `startCamera()` on the main thread, we use `viewFinder.post { ... }`
to make sure that `viewFinder` has already been inflated into the view when `startCamera()` is called.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextureView
dependencies {
def camerax_version = '1.0.0-alpha06'
...
implementation 'ai.fritz:core:4.2.0'
implementation "ai.fritz:vision:4.2.0"
...
implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-camera2:${camerax_version}"
}
val promptInfo = BiometricPrompt.PromptInfo.Builder()
.setTitle("Authentication prompt!")
/*Subtitle and description are optional parameters, so, you can skip those parameters.
.setSubtitle("Set the subtitle to display.")
.setDescription("Verification required")*/
.setNegativeButtonText("Cancel")
.build()
val biometricPrompt = BiometricPrompt(activity, executor, object : BiometricPrompt.AuthenticationCallback() {
override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {
super.onAuthenticationError(errorCode, errString)
if (errorCode == BiometricPrompt.ERROR_NEGATIVE_BUTTON) {
// user clicked negative/cancel button
} else {
TODO("Called when an unrecoverable error has been encountered and the operation is complete.")
}
}
dependencies {
def biometric_version = "1.0.0"
implementation fileTree(dir: 'libs', include: ['*.jar'])
...
implementation "androidx.biometric:biometric:$biometric_version"
}