How to get camera to only take image of an object


How can I go about implementing a feature where the ionic camera preview only takes picture of an object automatically if the object is in focus otherwise it won’t take the picture at all ?
One option I’m considering is using tensorflow.js for object recognition( to check if the object is the desired object and then take a picture), but I’m don’t know how to get the object in focus.

Any help is appreciated. Thanks.