Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Mat rotation center

Hi, I'm rotating the 10x1 image by specifying center at 5,0:

[255, 255, 255, 255, 255, 255, 255, 255, 255, 255]

int size = 10;
Mat test = Mat::zeros(Size(size, 1), CV_8U);
line(test, Point(0, 0), Point(size, 0), Scalar(255));

Mat rot = getRotationMatrix2D(Point(test.cols/2, test.rows/2), 90, 1);
Mat dest;
warpAffine(test, dest, rot, Size(size, size));

imshow("Source", test);
imshow("Result", dest);

I assume that result will be the vertical line at center of 10x10 Mat, but it is shifted and cropped to the top:

[  0,   0,   0,   0,   0, 255,   0,   0,   0,   0;
   0,   0,   0,   0,   0, 255,   0,   0,   0,   0;
   0,   0,   0,   0,   0, 255,   0,   0,   0,   0;
   0,   0,   0,   0,   0, 255,   0,   0,   0,   0;
   0,   0,   0,   0,   0, 255,   0,   0,   0,   0;
   0,   0,   0,   0,   0, 255,   0,   0,   0,   0;
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0;
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0;
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0;
   0,   0,   0,   0,   0,   0,   0,   0,   0,   0]

I'm trying to understand why it happens?