int ColorConvert(cv::Mat& source, cv::Mat& dest, int sType, int dType);
int Normalize(cv::Mat& source, cv::Mat& dest,
const std::vector<double>& mean, const std::vector<double>& std);
+ int Quantize(cv::Mat& source, cv::Mat& dest,
+ const std::vector<double>& scale, const std::vector<double>& zeropoint);
};
const std::vector<double>& mean, const std::vector<double>& std)
{
LOGI("ENTER");
+
try {
cv::subtract(source, cv::Scalar(mean[0], mean[1], mean[2]), dest);
source = dest;
return MEDIA_VISION_ERROR_NONE;
}
+ int PreProcess::Quantize(cv::Mat& source, cv::Mat& dest,
+ const std::vector<double>& scale, const std::vector<double>& zeropoint)
+ {
+ LOGI("ENTER");
+
+ try {
+ cv::subtract(source, cv::Scalar(zeropoint[0], zeropoint[1], zeropoint[2]), dest);
+ source = dest;
+ cv::multiply(source, cv::Scalar(scale[0], scale[1], scale[2]), dest);
+ } catch (cv::Exception& e) {
+ LOGE("Fail to subtract/multiply with msg: %s", e.what());
+ return MEDIA_VISION_ERROR_INVALID_OPERATION;
+ }
+
+ LOGI("LEAVE");
+
+ return MEDIA_VISION_ERROR_NONE;
+ }
+
int PreProcess::Run(cv::Mat& source, const int colorSpace,
const int dataType, const LayerInfo& layerInfo,
const Options& options, void* buffer)
Normalize(dest, dest, options.normalization.mean, options.normalization.std);
}
+ if (options.quantization.use) {
+ Quantize(dest, dest, options.quantization.scale, options.quantization.zeropoint);
+ }
+
LOGI("LEAVE");
return MEDIA_VISION_ERROR_NONE;