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
// 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) |
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
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) |
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
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 | |
} |
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
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) |
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
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. |
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
<?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 |
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
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}" | |
} |
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
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() |
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
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.") | |
} | |
} |
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
dependencies { | |
def biometric_version = "1.0.0" | |
implementation fileTree(dir: 'libs', include: ['*.jar']) | |
... | |
implementation "androidx.biometric:biometric:$biometric_version" | |
} |