Skip to content

Commit 32dedc3

Browse files
committed
Make rotation math more comprehensible
1 parent fb0e539 commit 32dedc3

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/Aardvark.OpenCV/ImageProcessing.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public PixImage<T> Rotate<T>(PixImage<T> image, double angleInRadians, bool resi
182182
// Compute bounds of rotated image
183183
// See: https://stackoverflow.com/questions/3231176/how-to-get-size-of-a-rotated-rectangle
184184
var cos = rotMat.At<double>(0, 0);
185-
var sin = rotMat.At<double>(1, 0);
185+
var sin = rotMat.At<double>(0, 1);
186186
var cosAbs = cos.Abs();
187187
var sinAbs = sin.Abs();
188188
dstSize.X = (long)(image.Width * cosAbs + image.Height * sinAbs + 0.5);
@@ -193,8 +193,8 @@ public PixImage<T> Rotate<T>(PixImage<T> image, double angleInRadians, bool resi
193193
// Shift by -dstCenter -> rotate CW -> shift by srcCenter.
194194
// See: https://math.stackexchange.com/questions/2093314/rotation-matrix-of-rotation-around-a-point-other-than-the-origin
195195
var dstCenter = dstSize.XY.ToV2d() * 0.5;
196-
rotMat.At<double>(0, 2) = -dstCenter.X * cos + dstCenter.Y * sin + srcCenter.X;
197-
rotMat.At<double>(1, 2) = -dstCenter.X * sin - dstCenter.Y * cos + srcCenter.Y;
196+
rotMat.At<double>(0, 2) = -dstCenter.X * cos - dstCenter.Y * sin + srcCenter.X;
197+
rotMat.At<double>(1, 2) = dstCenter.X * sin - dstCenter.Y * cos + srcCenter.Y;
198198
}
199199

200200
var dst = dstSize.CreateImageVolume<T>();

0 commit comments

Comments
 (0)