Last active
October 22, 2018 14:55
-
-
Save prabindh/852787042c1f0246132ffa4b17f4e220 to your computer and use it in GitHub Desktop.
Letterbox resize for Arapaho (https://github.com/prabindh/darknet/issues/72)
This file contains hidden or 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
// Call like below | |
// boxedMat will contain resized image | |
// boxedMat = __LetterBoxResize(floatMat, net->w, net->h); | |
// | |
// Taken mostly from https://jdhao.github.io/2017/11/06/resize-image-to-square-with-padding/ | |
cv::Mat ArapahoV2::__LetterBoxResize(cv::Mat img, int w, int h) | |
{ | |
cv::Mat intermediateImg, outputImg; | |
int delta_w, delta_h, top, left, bottom, right; | |
int new_w = img.size().width; | |
int new_h = img.size().height; | |
if (((float)w / img.size().width) < ((float)h / img.size().height)) { | |
new_w = w; | |
new_h = (img.size().height * w) / img.size().width; | |
} | |
else { | |
new_h = h; | |
new_w = (img.size().width * h) / img.size().height; | |
} | |
cv::resize(img, intermediateImg, cv::Size(new_w, new_h)); | |
delta_w = w - new_w; | |
delta_h = h - new_h; | |
top = floor(delta_h / 2); | |
bottom = delta_h - floor(delta_h/2); | |
left = floor(delta_w / 2); | |
right = delta_w - floor(delta_w/2); | |
cv::copyMakeBorder(intermediateImg, outputImg, top, bottom, left, right, cv::BORDER_CONSTANT, (0,0,0)); | |
return outputImg; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you update the code since my last pull request on fixArapahoLibDarknetUsed, I will test it. Thanks