in Transform360/Library/VideoFrameTransform.cpp [742:833]
bool VideoFrameTransform::transformPlane(
const Mat& inputMat,
Mat& outputMat,
int outputWidth,
int outputHeight,
int transformMatPlaneIndex,
int imagePlaneIndex) {
// For Barrel layout we want to have some black spots on the video frame,
// so we need to change border mode to transparent, to avoid overwriting them.
int borderMode =
(ctx_.output_layout == LAYOUT_BARREL ||
ctx_.output_layout == LAYOUT_BARREL_SPLIT) ?
BORDER_TRANSPARENT :
BORDER_WRAP;
try {
switch (ctx_.interpolation_alg) {
case NEAREST:
case LINEAR:
case CUBIC:
case LANCZOS4:
{
Mat tempMat;
if (ctx_.enable_low_pass_filter) {
// Filter frame plane with filters
tempMat = filterPlane(
inputMat,
transformMatPlaneIndex,
imagePlaneIndex);
} else {
tempMat = inputMat;
}
bool needResize =
(outputHeight != warpMats_[transformMatPlaneIndex].rows ||
outputWidth != warpMats_[transformMatPlaneIndex].cols);
if (!needResize) {
// We want to set default YUV values to 0.
// UV (plane index > 0) planes are scaled from [-1, 1],
// so we set it to 128.
if (transformMatPlaneIndex &&
(ctx_.output_layout == LAYOUT_BARREL ||
ctx_.output_layout == LAYOUT_BARREL_SPLIT)) {
outputMat.setTo(Scalar(128));
}
remap(
tempMat,
outputMat,
warpMats_[transformMatPlaneIndex],
cv::Mat(),
ctx_.interpolation_alg,
borderMode);
} else {
// We want to set default YUV values to 0.
// UV (plane index > 0) planes are scaled from [-1, 1],
// so we set it to 128.
Mat scaledWarpedImage(
warpMats_[transformMatPlaneIndex].size(),
tempMat.type(),
Scalar(transformMatPlaneIndex ? 128 : 0));
remap(
tempMat,
scaledWarpedImage,
warpMats_[transformMatPlaneIndex],
cv::Mat(),
ctx_.interpolation_alg,
borderMode);
resize(
scaledWarpedImage,
outputMat,
Size(outputWidth, outputHeight),
0,
0,
INTER_AREA);
}
break;
}
default:
printf(
"Could not find interpolation algorithm for plane %d",
imagePlaneIndex);
}
} catch (const exception& ex) {
printf(
"Could not transform the plane %d. Error: %s\n",
imagePlaneIndex,
ex.what());
return false;
}
return true;
}