Last active
November 2, 2018 17:25
-
-
Save the-dagger/f0e4e4732d8e0a79d78354225eb263d5 to your computer and use it in GitHub Desktop.
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 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