class MainActivity : AppCompatActivity() { | |
//Map that will contain a key-value combination of detected items | |
private val itemMap by lazy { | |
hashMapOf<String, Int>() | |
} | |
override fun onCreate(savedInstanceState: Bundle?) { | |
val objectPredictor = FritzVisionObjectPredictor.getInstance(this) | |
var fritzVisionImage: FritzVisionImage | |
cameraView.addFrameProcessor { frame -> | |
//Rest of the code | |
fritzVisionImage = FritzVisionImage.fromBitmap(bitmapOut) | |
//Get a list of items that were detected in the Image | |
val visionObjects = objectPredictor.predict(fritzVisionImage) | |
//Clear the existing map | |
itemMap.clear() | |
//Convert the list of objects detected into a Map so that we can track count of similar items | |
visionObjects.forEach { visionObject -> | |
if (itemMap.containsKey(visionObject.visionLabel.text)) | |
itemMap[visionObject.visionLabel.text] = itemMap[visionObject.visionLabel.text]!! + 1 | |
itemMap[visionObject.visionLabel.text] = 1 | |
} | |
//Print the detected items on the screen | |
runOnUiThread { | |
tvDetectedItem.text = "" | |
itemMap.forEach { map -> | |
tvDetectedItem.append("Detected ${map.value} ${map.key}\n") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment