它还没有被提及,所以我将指出 OpenCV 具有缩放和旋转图像的功能,以及大量其他实用程序。它可能包含许多与问题无关的功能,但它很容易设置和用于此类库。
您可以尝试手动实现这样的转换,但简单的缩放和旋转方法通常会导致大量细节丢失。
使用 OpenCV,可以像这样进行缩放:
float scaleFactor = 0.68f;
cv::Mat original = cv::imread(path);
cv::Mat scaled;
cv::resize(original, scaled, cv::Size(0, 0), scaleFactor, scaleFactor, cv::INTER_LANCZOS4);
cv::imwrite("new_image.jpg", scaled);
这使用 Lanczos 插值将图像缩小了 0.68 倍。
我对旋转不太熟悉,但这里是 OpenCV 网站上的教程之一的示例的一部分,我已将其编辑到相关部分。(原文也有歪曲和翻译...)
/// Compute a rotation matrix with respect to the center of the image
Point center = Point(original.size().width / 2, original.size().height / 2);
double angle = -50.0;
double scale = 0.6;
/// Get the rotation matrix with the specifications above
Mat rot_mat( 2, 3, CV_32FC1 );
rot_mat = getRotationMatrix2D(center, angle, scale);
/// Rotate the image
Mat rotated_image;
warpAffine(src, rotated_image, rot_mat, src.size());
OpenCV 网站
他们也有一些非常好的文档。