Wednesday, September 9, 2009

C++ Implementation of Correspondence Matching


As introduced in the previous articles, to realize the target tracking by single camera, there are already some mature algorithms and methods available. But most of them based on an assumption that the correspondence between the target markers and detected image points are known. While in fact except some active markers which can be distinguished by frequency, the correspondence is always an unknown variable. So even with the PnP algorithm like POSIT or DLT, reconstruct the 3D coordinate values of the markers, it is also possible that because of the wrong correspondence, this reconstruction or the achieved 3D value was incorrect. So it is relevant that after the PnP algorithm, project the 3D CS onto the sensor image plane again, and with some method, like evaluating the minimal mean squared distance, to make sure the correct correspondence. With the new correspondence reference, the 3D reconstruction will be implemented again or iteratively. The image illustrates such a situation.

And here I would like to offer my C++ implementation of such a solution for the 2D to 2D correspondence. The line of thought with the implementation is as follows:

given: the order-known (with determined order:1 2 3... ) points set
the order-unknown points set
threshold: the minimal distance between the points, if the distance is larger than it, the correspondence determination makes no sense any more

to obtain: the correct correspondence between these two sets

How to run it:
for all red points with known CS
for all green points with known CS
calculate all of the possible distances between each other;
if (Di is smaller than threshold and Di is the minimal distance)
the order of this green point belongs to the ith red point;
end
end
end

The output is below:


We can check the result easily that after the correspondence operation, the order of two sets match each other correctly. And in my another project which is related to the one camera reconstruction problem, this function works also efficiently to improve the transformation matrix. And I will attach my C++ code of the implementation which is run under the Visual Studio 2008. I hope it could help you guys. Enjoy it!!

0 comments: