From b5107bfc5a1a372421603e7efb8f029f6bdb5a38 Mon Sep 17 00:00:00 2001 From: uvos Date: Tue, 20 Jul 2021 23:19:22 +0200 Subject: [PATCH] improve kfactor support --- src/argpopt.h | 7 ++++- src/main.cpp | 12 ++++---- src/unwrap.cpp | 63 ++++++++++++++++++++--------------------- src/uvosunwrap/unwrap.h | 3 +- 4 files changed, 45 insertions(+), 40 deletions(-) diff --git a/src/argpopt.h b/src/argpopt.h index 7bee75a..7a1828e 100644 --- a/src/argpopt.h +++ b/src/argpopt.h @@ -35,6 +35,7 @@ struct Config bool quiet = false; bool interactive = false; bool simpleStich = false; + float kFactor = 0; }; const char *argp_program_version = "0.2"; @@ -56,6 +57,7 @@ static struct argp_option options[] = {"interactive", 'i', 0, 0, "interactivly process multiple commands" }, {"simpe-stich", 'a', 0, 0, "Use non blending sticher" }, {"curve", 'c', "File Name", 0, "curve file name" }, +{"kfactor", 'k', "Value", 0, "set the kfactor" }, { 0 } }; @@ -78,7 +80,7 @@ error_t parse_opt (int key, char *arg, struct argp_state *state) config->norm.assign(arg); break; case 's': - config->minSize=atol(arg); + config->minSize=strtod(arg, nullptr); break; case 'r': config->harris = true; @@ -98,6 +100,9 @@ error_t parse_opt (int key, char *arg, struct argp_state *state) case 'c': config->curve.assign(arg); break; + case 'k': + config->kFactor=strtod(arg, nullptr); + break; case ARGP_KEY_ARG: config->commandsFiles = &state->argv[state->next-1]; state->next = state->argc; diff --git a/src/main.cpp b/src/main.cpp index 42b37c1..8f8c5a1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -242,12 +242,14 @@ int perfromOperation(int operation, char** fileNames, const Config& config) { cv::imshow( "Viewer", remaped.image ); cv::waitKey(0); - cv::imshow( "Viewer", remaped.angleX); + cv::imshow( "Viewer", remaped.angle); cv::waitKey(0); - cv::imshow( "Viewer", remaped.angleY); - cv::waitKey(0); - applyKfactor(remaped.image, remaped.angleX, 3); - cv::imshow( "remaped.image", remaped.image ); + } + + applyKfactor(remaped.image, remaped.angle, config.kFactor); + if(config.verbose) + { + cv::imshow("Viewer", remaped.image ); cv::waitKey(0); } diff --git a/src/unwrap.cpp b/src/unwrap.cpp index 79abb46..3b7b113 100644 --- a/src/unwrap.cpp +++ b/src/unwrap.cpp @@ -176,41 +176,43 @@ void applyKfactor(cv::Mat& image, const cv::Mat& angleMat, float kFactor) } } -static void generateAngleMats(const cv::Mat& xMat, const cv::Mat& yMat, cv::Mat& xStrech, cv::Mat& yStrech) +static void generateAngleMats(const cv::Mat& xMat, const cv::Mat& yMat, cv::Mat& greatestAngle) { - 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++) + std::cout<(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); + cv::Point2f pA(xMat.at(y,x), yMat.at(y,x)); + cv::Point2f pB(xMat.at(y,x+1), yMat.at(y,x+1)); + cv::Point2f pC(xMat.at(y+1,x), yMat.at(y+1,x)); + double normX = cv::norm(pA-pB); + double normY = cv::norm(pA-pC); + + if(normX > max) + max = normX; + if(normY > max) + max = normY; } } - for(int x = 0; x < yMat.cols; x++) + for(int y = 0; y < xMat.rows-1; y++) { - float max = 0; - for(int y = 0; y < yMat.rows-1; y++) + for(int x = 0; x < xMat.cols-1; x++) { - float strech = yMat.at(y,x) - yMat.at(y+1,x); - if(strech > max) - max = strech; + cv::Point2f pA(xMat.at(y,x), yMat.at(y,x)); + cv::Point2f pB(xMat.at(y,x+1), yMat.at(y,x+1)); + cv::Point2f pC(xMat.at(y+1,x), yMat.at(y+1,x)); + double normX = cv::norm(pA-pB); + double normY = cv::norm(pA-pC); + + greatestAngle.at(y,x) = 1-(std::min(normX, normY)/max); + + if(y == 0) + Log(Log::DEBUG)<(y,x); } - 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; } } @@ -223,13 +225,10 @@ RemapedImage applyRemap(const cv::Mat& image, const RemapMap &map) 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); + generateAngleMats(map.xMat, map.yMat, out.angle); + cv::Mat angleResized; + cv::resize(out.angle, angleResized, outputSize, cv::INTER_LINEAR); + out.angle = angleResized(noBorderRoi); cv::resize(map.xMat, xMapResized, outputSize, cv::INTER_LINEAR); cv::resize(map.yMat, yMapResized, outputSize, cv::INTER_LINEAR); diff --git a/src/uvosunwrap/unwrap.h b/src/uvosunwrap/unwrap.h index 3ad470f..185abbf 100644 --- a/src/uvosunwrap/unwrap.h +++ b/src/uvosunwrap/unwrap.h @@ -25,8 +25,7 @@ struct RemapedImage { cv::Mat image; - cv::Mat angleX; - cv::Mat angleY; + cv::Mat angle; cv::Point2i origin; };