Last active
January 24, 2022 12:20
-
-
Save doleron/53ec8f00bc22e8e13704841bda16081d to your computer and use it in GitHub Desktop.
C++ format input
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
cv::Mat format_yolov5(const cv::Mat &source) { | |
// put the image in a square big enough | |
int col = source.cols; | |
int row = source.rows; | |
int _max = MAX(col, row); | |
cv::Mat resized = cv::Mat::zeros(_max, _max, CV_8UC3); | |
source.copyTo(resized(cv::Rect(0, 0, col, row))); | |
// resize to 640x640, normalize to [0,1[ and swap Red and Blue channels | |
cv::Mat result; | |
cv::dnn::blobFromImage(source, result, 1./255., cv::Size(INPUT_WIDTH, INPUT_HEIGHT), cv::Scalar(), true, false); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment