Skip to content

Instantly share code, notes, and snippets.

View DongHeZheng's full-sized avatar

郑东赫 DongHeZheng

  • Freelancer
  • China, Beijing
View GitHub Profile
@DongHeZheng
DongHeZheng / .cpp
Last active May 6, 2024 12:45
One method of scaling, rotating and cropping image by using OpenCV
void imageScaleAndRotate(const cv::Mat &src, cv::Mat &out, double scale, double roll) {
// scaling
cv::Mat imSmall;
cv::resize(src, imSmall, cv::Size(), scale, scale);
// prepare for rotating
int width = imSmall.cols, height = imSmall.rows;
int diagonal = int(sqrt(height * height + width * width));
int offsetX = (diagonal - width) / 2, offsetY = (diagonal - height) / 2;