# Revision history [back]

I can't belived this is working:

Mat templateImage = ("template.jpg");


It won't on my computer.

Mat templateImage = imread("template.jpg");


I assume copy/paste issue?

Don't use cvCreateMat with the CPP interface:

Mat graySourceImage(sourceImage.rows,sourceImage.cols,CV_32FC1);


This is more "c++" like, and a compact way of writing it.

Idem for:

sourceImage.copyTo(destinationImage); //Old
destinationImage = sourceImage.clone(); //Become


For the rotation, I suggest looking at this way, with wrapAffine, adapted from that sample.

Point center = Point( ori.cols/2, ori.rows/2 );
double angle = -50.0;
double scale = 1.;
/// Get the rotation matrix with the specifications above
Mat rot_mat( 2, 3, CV_32FC1 );
rot_mat = getRotationMatrix2D( center, angle, scale );
/// Rotate the warped image
warpAffine( ori, dst, rot_mat, ori.size() );


The more you use OpenCV function, the more you will enjoy for free the speed up available in these function. You could also use your GPU to make all the process, and thanks to these functions, you don't need CPU/GPU transfers!

After all these fixes, if it doesn't work, try to see all your intermediate images and be sure they are properly loaded.