MCPcopy Create free account
hub / github.com/MegEngine/MegCC / preprocess

Function preprocess

yolox_example/main.cpp:92–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90};
91
92static void preprocess(cv::Mat& img, float* data_ptr) {
93 float r = std::min(INPUT_W / (img.cols * 1.0), INPUT_H / (img.rows * 1.0));
94 int unpad_w = r * img.cols;
95 int unpad_h = r * img.rows;
96 cv::Mat re(unpad_h, unpad_w, CV_8UC3);
97 cv::resize(img, re, re.size());
98 cv::Mat resize_img(INPUT_W, INPUT_H, CV_8UC3, cv::Scalar(114, 114, 114));
99 re.copyTo(resize_img(cv::Rect(0, 0, re.cols, re.rows)));
100
101 cv::cvtColor(resize_img, resize_img, cv::COLOR_BGR2RGB);
102 int channels = 3;
103 int img_h = resize_img.rows;
104 int img_w = resize_img.cols;
105 std::vector<float> mean = {0.485, 0.456, 0.406};
106 std::vector<float> std = {0.229, 0.224, 0.225};
107 for (size_t c = 0; c < channels; c++) {
108 for (size_t h = 0; h < img_h; h++) {
109 for (size_t w = 0; w < img_w; w++) {
110 data_ptr[c * img_w * img_h + h * img_w + w] =
111 (((float)resize_img.at<cv::Vec3b>(h, w)[c]) / 255.0f -
112 mean[c]) /
113 std[c];
114 }
115 }
116 }
117}
118
119static inline float intersection_area(const OutputInfo& a, const OutputInfo& b) {
120 cv::Rect_<float> inter = a.rect & b.rect;

Callers 1

mainFunction · 0.85

Calls 1

minFunction · 0.85

Tested by

no test coverage detected