OpenCv has the tools and classes required for it. But you will need to create your own algorithm (not simple) based on them. Also, there can be different approaches.
I would start by googling the thread title adding Opencv: if a working approach appears ( regardless if it is in python, c++ or Java) and the required subclasses used in this approach are included in OpenCv B4A lib, you got a good starting point, as it would 'only' need translation to B4A.
(Perhaps there exist more specific B4A libs that directly face this specific need, but I don't know of them)