# Revision history [back]

You could rotate the image first and then extract the rectangle, but if the rectangle is small compared to the full image it might be better tor use warpAffine.

Allocate the destination image with the size of the rectangle.

I think the affine transformation matrix is

T=[ 1 0 x0 ]
[ 0 1 y0 ]
R=[ cos(theta) -sin(theta) 0 ]
[ sin(theta)  cos(theta) 0 ]
[      0           0     1 ]
M=T(x0,y0)*R(theta)
=[ cos(theta) -sin(theta) x0 ]
[ sin(theta)  cos(theta) y0 ]


Where x0,y0 is the coordinate of the upper-left corner of the rectangle and theta is the rotation angle. I haven't tested this, so there may be an error in this definition but it should be a good start.