what I'm trying to do is transforming an image using an (Matlab) transformation matrix. It is the following 2D transformation matrix with a 3x3 dimension:
aaa bbb 0 ccc ddd 0 eee fff 1
I found a pretty good explanation here: how to transform an image with a transformation Matrix in OpenCv? but I'm not able to fill the 3x3 matrix (and apply it to the image). This is my code:
cv::Mat t(3,3,CV_64F,cvScalar(0.0));
t.at<double>(0, 0) = aaa;
t.at<double>(1, 0) = bbb;
t.at<double>(2, 0) = 0;
t.at<double>(0, 1) = ccc;
t.at<double>(1, 1) = ddd;
t.at<double>(2, 1) = 0;
t.at<double>(0, 2) = eee;
t.at<double>(1, 2) = fff;
t.at<double>(2, 2) = 1;
cv::Mat dest;
cv::Size size(imageToTransform.cols,imageToTransform.rows);
warpAffine(imageToTransform, outputImage, t, size, INTER_LINEAR, BORDER_CONSTANT);
imshow("outputImage", outputImage);
Causes the following error:
OpenCV Error: Assertion failed ((M0.type() == CV_32F || M0.type() == CV_64F) && M0.rows == 2 && M0.cols == 3)
Any idea whats wrong here?
cv::Mat t(3,3,CV_64F,cvScalar(0.0));not 3 rows? - flor1anwarpAffinefunction requires that the transformation matrix is 2x3 matrix but in your case it is 3x3 matrix. - Lakshya Kejriwal