Since there have been some questions about an example, I will show you how to use the CThinPlateSpline-Class. First of all we have to load an image from our disk. The image can be of any size, depth or color format. Just call
// load a nice picture
cv::Mat img = cv::imread("C:\\lena512color.jpg");
Now that we have an image we should set some reference points on which the spline algorithm will evaluate the distortion. Normally you would use a interest point detector, but it was easier to just add some generic points to the dataset.
// generate some generic points
// usually you would use a interest point detector such as SURF or SIFT
std::vector
// push some points into the vector for the source image
iP.push_back(cv::Point(50,50));
iP.push_back(cv::Point(400,50));
iP.push_back(cv::Point(50,400));
iP.push_back(cv::Point(400,400));
iP.push_back(cv::Point(256,256));
iP.push_back(cv::Point(150,256));
// push some point into the vector for the dst image
iiP.push_back(cv::Point(70,70));
iiP.push_back(cv::Point(430,60));
iiP.push_back(cv::Point(60,410));
iiP.push_back(cv::Point(430,420));
iiP.push_back(cv::Point(220,280));
iiP.push_back(cv::Point(180,240));
Now we have already done the tedious part, lets create a CThinPlateSpline object that will do all the work for you.
// create thin plate spline object and put the vectors into the constructor
CThinPlateSpline tps(iP,iiP);
The only thing we have to do now is to call the internal warping function and set the correct parameters.
// warp the image to dst
Mat dst;
tps.warpImage(img,dst,0.01,INTER_CUBIC,BACK_WARP);
To see the results just call the imshow function out of opencv
// show images
cv::imshow("original",img);
cv::imshow("distorted",dst);
cv::waitKey(0);
Because it's quite a tradition I used our good old gal "lena" to show you the advantages of the spline algorithm. Just take a look.