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
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
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
// 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
package com.lavanya.imagelabeling | |
import ai.fritz.core.Fritz | |
import ai.fritz.vision.FritzVision | |
import ai.fritz.vision.FritzVisionImage | |
import ai.fritz.vision.ImageRotation | |
import ai.fritz.vision.PredictorStatusListener | |
import ai.fritz.vision.imagelabeling.FritzVisionLabelPredictor | |
import ai.fritz.vision.imagelabeling.ImageLabelManagedModelFast | |
import android.os.Bundle |
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" | |
tools:context=".MainActivity"> | |
<TextureView | |
android:id="@+id/view_finder" |
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
/* It allows us to define a custom class implementing the ImageAnalysis.Analyzer interface, | |
which will be called with incoming camera frames. | |
*/ | |
class ImageProcessor : ImageAnalysis.Analyzer { | |
var predictor: FritzVisionStylePredictor? = null | |
val TAG = javaClass.simpleName | |
override fun analyze(image: ImageProxy?, rotationDegrees: Int) { | |
//Handle all the ML logic here |
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: FritzVisionStylePredictor? = null | |
val managedModel = PaintingManagedModels.BICENTENNIAL_PRINT_MANAGED_MODEL | |
/* Load the FritzVision Style Transfer Predictor | |
*/ | |
FritzVision.StyleTransfer.loadPredictor( | |
managedModel, object : PredictorStatusListener<FritzVisionStylePredictor> { | |
override fun onPredictorReady(stylePredictor: FritzVisionStylePredictor?) { | |
Log.d(TAG, "Style Transfer predictor is ready") | |
predictor = stylePredictor |
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) | |
/* Get the FritzVisionStyleResult by running the predictor on the vision image. | |
*/ | |
val styleResult = predictor?.predict(visionImage) | |
/* Perform UI operations accordingly. | |
*/ |