Great job Francois,
But i have still a problem with this code. The code moves the orientation of the object to find coordinates (as we can see in your picture to introduce your code).
In my case is very important to keep the initial object in the same axis system. To be more clear i want to record with a fixed camera several binary images of an object which will be a little perturbated. So if i want to compare the perturbated object with a non-perturbated one, i need to keep the same axis system (for exemple, the entire image).
I hope have been enough clear about my problem.
Thx again for your sharing.