There are two ways that I know you can register images with openCV. Feature based registration, and pixel based registration. I can see that you already have reference points to work with to register your image, so you could use techniques used in feature based registration.
Like you say, you have a reference image and a image to register. With the points that you have computed with the homemade algorithm, you could use the "findHomography( )" function. --> Mat H = findHomography(ImageToRegister_pts, ReferenceImage_pts, CV_RANSAC);
where ImageToRegister_pts and ReferenceImage_pts are vector<Point2f>
of your points This will give you the homography matrix between the two images which you can use to warp/align the given image to the reference image. (Reference: http://docs.opencv.org/modules/calib3...)
Then use the "warpPerspective function( )" to effectively warp the image. --> warpPerspective(imageToWarp, OutputImage, Hinv, ImageToWarp.size());
where ImageToWarp is the Mat image, OutputImage is a Mat to store the final output and Hinv is the inverse of the Homography Matrix (Hinv = H.inv()
). There are alternatives to the warPerspective function like "perspectiveTransform( )" as used in this example --> http://docs.opencv.org/doc/tutorials/...
Another registration technique can be found in OpenCV 3 under the opencv_contrib functionality. It uses pixel based registration methods. Follow this link for more information --> https://github.com/Itseez/opencv_cont...
As per my experience, I used feature based registration as it was simpler, however pixel based registration is more accurate. You will have to look into the source code to really understand what is happening. Your choice all depends on your application.
Hope this helps!