Detect if image is blurry using pytorch android API

Viewed 333

So I am working in this app in which if an officer take a picture of car accident and if this picture is blur, it will no accept it. It will only allow images based on quality and resolution. So after research, I found that I can implement this feature using pytorch in which I will save it in my asset and then write kotlin code based on my logic. I found this link: https://pytorch.org/mobile/android/ However, this link shows image classifier example in which user can detect if the image is a cat or a dog, and this is not what I want.

As an example,

If a police officer take a picture via the app of car accident, the app needs to verify if the image resolution and quality is readable and understandable so when user sees the image taken he/she can tell if it is car accident compared to that of when it is blur image and not clear the app will ask the user to take a picture again.

Any tips please ?

Thank you

1 Answers

For a start you can try to build this using conventional computer vision algorithms. You will find a few examples trying to implement a similar idea using OpenCV (e.g. here).

If you want to solve such a task through machine learning, you either can try to find a model that is trained to solve such a task online (maybe you can find one if you are lucky), or you have to train such a model yourself.

When using machine learning you need to have a dataset, which in your case you can easily create from a database of images and blurring the examples yourself (see self-supervised learning). You need to decide which machine learning method to use. For a simple detection if an image is blurry, using deep learning and CNNs seems unnecessary. Instead look into extracting some features relating to an images bluriness and use a simple machine learning algorithms such as k-NN.

However I think using machine learning to solve this kind of task is not really necessary. Every digital camera is basically implementing this feature for their autofocus. So I think looking for conventional computer vision solutions with OpenCV, (e.g. edge contrast estimation, image frequency transforms, ...) will get you to your goal quicker.

OpenCV is also available for Android SDK.

Related