From f2d5a905e8d792f17372ed71736d05ede0fc62d8 Mon Sep 17 00:00:00 2001 From: uvos Date: Tue, 20 Jul 2021 15:33:29 +0200 Subject: [PATCH] add support for kfactor --- src/main.cpp | 12 ++++++- src/unwrap.cpp | 70 +++++++++++++++++++++++++++++++++++++++-- src/uvosunwrap/unwrap.h | 4 +++ 3 files changed, 83 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 23d6265..42b37c1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -211,7 +211,10 @@ int perfromOperation(int operation, char** fileNames, const Config& config) map.outputCellSize = config.size; if(!map.xMat.data) + { + Log(Log::ERROR)<<"could not load remap map from "<(y); + const float* anglex = angleMat.ptr(y); + for(int x = 0; x < image.cols; x++) + { + int value = colx[x]*(1-(anglex[x]*kFactor)); + if(value < 0) + value = 0; + else if(value > 255) + value = 255; + colx[x] = value; + } + } +} + +static void generateAngleMats(const cv::Mat& xMat, const cv::Mat& yMat, cv::Mat& xStrech, cv::Mat& yStrech) +{ + xStrech.create(xMat.rows, xMat.cols-1, CV_32FC1); + yStrech.create(yMat.rows-1, xMat.cols, CV_32FC1); + for(int y = 0; y < xMat.rows; y++) + { + const float* colx = xMat.ptr(y); + float max = 0; + for(int x = 0; x < xMat.cols-1; x++) + { + float strech = std::abs(colx[x]-colx[x+1]); + if(strech > max) + max = strech; + } + if(y == 0) + Log(Log::DEBUG)<<"AngleX on x"; + for(int x = 0; x < xMat.cols-1; x++) + { + xStrech.at(y,x) = 1-std::abs(colx[x]-colx[x+1])/max; + if(y == 0) + Log(Log::DEBUG)<(y,x); + } + } + + for(int x = 0; x < yMat.cols; x++) + { + float max = 0; + for(int y = 0; y < yMat.rows-1; y++) + { + float strech = yMat.at(y,x) - yMat.at(y+1,x); + if(strech > max) + max = strech; + } + for(int y = 0; y < yMat.rows-1; y++) + yStrech.at(y,x) = 1-std::abs(yMat.at(y,x) - yMat.at(y+1,x))/max; + } +} + RemapedImage applyRemap(const cv::Mat& image, const RemapMap &map) { RemapedImage out; cv::Mat xMapResized; cv::Mat yMapResized; const cv::Size outputSize(map.outputCellSize*map.xMat.cols,map.outputCellSize*map.xMat.rows); + cv::Rect noBorderRoi(map.outputCellSize/2, map.outputCellSize/2, + outputSize.width-map.outputCellSize, outputSize.height-map.outputCellSize); + + generateAngleMats(map.xMat, map.yMat, out.angleX, out.angleY); + cv::Mat angleXResized; + cv::Mat angleYResized; + cv::resize(out.angleX, angleXResized, outputSize, cv::INTER_LINEAR); + cv::resize(out.angleY, angleYResized, outputSize, cv::INTER_LINEAR); + out.angleX = angleXResized(noBorderRoi); + out.angleY = angleYResized(noBorderRoi); cv::resize(map.xMat, xMapResized, outputSize, cv::INTER_LINEAR); cv::resize(map.yMat, yMapResized, outputSize, cv::INTER_LINEAR); - cv::Rect noBorderRoi(map.outputCellSize/2, map.outputCellSize/2, - outputSize.width-map.outputCellSize, outputSize.height-map.outputCellSize); + cv::Mat xMapRed = xMapResized(noBorderRoi); cv::Mat yMapRed = yMapResized(noBorderRoi); cv::remap(image, out.image, xMapRed, yMapRed, cv::INTER_LINEAR); diff --git a/src/uvosunwrap/unwrap.h b/src/uvosunwrap/unwrap.h index 0bcc383..3ad470f 100644 --- a/src/uvosunwrap/unwrap.h +++ b/src/uvosunwrap/unwrap.h @@ -25,6 +25,8 @@ struct RemapedImage { cv::Mat image; + cv::Mat angleX; + cv::Mat angleY; cv::Point2i origin; }; @@ -44,5 +46,7 @@ bool createRemapMap(const cv::Mat& image, RemapMap& out, const std::vector& images, bool seamAdjust = false); cv::Mat simpleStich(const std::vector& images);