Created
March 9, 2015 19:10
-
-
Save wlucas-DFT/7e21bbcdf2e6128639e3 to your computer and use it in GitHub Desktop.
Does a simple percentage based center crop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mat centerCropMat(const cv::Mat& image, double cropPercentage) | |
{ | |
cropPercentage = min(cropPercentage, 1.0); | |
int newRows = (int)floor(image.rows * cropPercentage + 0.5); | |
int newCols = (int)floor(image.cols * cropPercentage + 0.5); | |
Point center(image.cols / 2, image.rows / 2); | |
Rect roi( | |
center.x - (newCols / 2), | |
center.y - (newRows / 2), | |
newCols, | |
newRows | |
); | |
return image(roi).clone(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment