Skip to content

Instantly share code, notes, and snippets.

@the-dagger
Last active November 2, 2018 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save the-dagger/f0e4e4732d8e0a79d78354225eb263d5 to your computer and use it in GitHub Desktop.
Save the-dagger/f0e4e4732d8e0a79d78354225eb263d5 to your computer and use it in GitHub Desktop.
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