JavaCV或OpenCV图像旋转

4
我的目标是以一定的角度(例如30度)旋转图像。在OpenCV中,通过tenta4进行90度旋转的可能方法只执行90度翻转,这一点很不幸。
另一种可能的方法是在JavaCV样本中给出的“SkewGrayImage”方法,在该方法中执行“小角度旋转”,似乎适用于大约45 - 50度的旋转,但不适用于任何其他更高的值。
因此,我的问题是,是否有在OpenCV或JavaCV中实际执行图像或对象的角度旋转的正确方法/方法?

1
请点击此处查看C++示例。 - Catree
4个回答

4

Meta已经解释了如何计算关于图像中心的旋转矩阵,并按以下步骤执行旋转:

    Mat rotated_image;
    warpAffine(src, rotated_image, rot_mat, src.size());

2

关于IplImage旋转的更详细解释可以参考Martin的回答,该回答基于Mat变量,可将其转换并返回为以下的IplImage:

Mat source = imread(argv[1], CV_LOAD_IMAGE_COLOR);
Mat rotation_matrix = getRotationMatrix2D(src_center, angle, 1.0);
Mat destinationMat;
warpAffine(source, destinationMat, rotation_matrix, source.size());
IplImage iplframe = IplImage(destinationMat);

2

1
希望这可以帮到你!对我来说,使用JavaCV可以实现。
Mat raw = ... // your raw mat

// Create your "new" Mat and the center of your Raw Mat
Mat result = new Mat(raw.size(), [your Image Type]); // my Img type was CV_8U
Point2f rawCenter = new Point2f(raw.cols() / 2.0F, raw.rows() / 2.0F);

// Scale and Rotation of new Mat
double scale = 1.0;
int rotation = -5;

// Rotation Matrix
Mat rotationMatrix = getRotationMatrix2D(rawCenter, rotation, scale);

// Rotate 
warpAffine(raw, result, rotationMatrix, raw.size());

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接