它還沒有被提及,所以我會指出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);
這通過使用蘭克澤斯插值的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 Website
They have some very nice documentation too.
雖然這在理論上可以回答這個問題,[但最好(// meta.stackoverflow .com/q/8259)在這裏包括答案的基本部分,並提供供參考的鏈接。 – 2016-08-31 13:43:36