kcv_normalAndNCHW
Usage
Performs normalization, the result of which is used as the input of deep learning models. It is optimized based on the user-defined normalAndNCHW interface.
Interface
1 2 | int kcv_normalAndNCHW( cv::Mat &mat, const std::array<float, 3> &mean, const std::array<float, 3> &std, float *outBuf, int mode); |
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
mat |
Input image. |
Not null, floating point, 3-channel |
Input |
mean |
Mean value of each channel. |
Floating point number less than 1 |
Input |
std |
Standard deviation of each channel. |
Floating point number less than 1 |
Input |
mode |
Operation mode. |
|
Input |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include <gtest/gtest.h> #include <opencv2/opencv.hpp> #include <algorithm> #include "KPCV/kcv.h" TEST(normalAndNCHW, normal) { Mat m_mat = src.clone(); m_mat.convertTo(m_mat, CV_32F, 1.0 / 255); std::array<float, 3> mean = {0.25603, 0.29465, 0.3477}; std::array<float, 3> std = {0.18766, 0.16251, 0.19558}; int testTime = 100; cv::TickMeter tm; int img_h = m_mat.rows; int img_w = m_mat.cols; int hw = img_h * img_w; int pc = img_h * img_w * 3; std::vector<float> simple1_opencv(pc), simple2_opencv(pc), withMeanStd1_opencv(pc), withMeanStd2_opencv(pc); // simple1 normalAndNCHW(m_mat, simple1_opencv.data(), 0); // simple2 normalAndNCHW(m_mat, simple2_opencv.data(), 1); // withMeanStd1 normalAndNCHW(m_mat, mean, std, withMeanStd1_opencv.data(), 2); // withMeanStd2 normalAndNCHW(m_mat, mean, std, withMeanStd2_opencv.data(), 3); } |
Parent topic: Interface Definition