improve kfactor support

This commit is contained in:
2021-07-20 23:19:22 +02:00
parent f2d5a905e8
commit b5107bfc5a
4 changed files with 45 additions and 40 deletions

View File

@ -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;

View File

@ -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);
}

View File

@ -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<<xMat<<std::endl;
greatestAngle.create(xMat.rows-1, xMat.cols-1, CV_32FC1);
double max = 0;
for(int y = 0; y < xMat.rows-1; y++)
{
const float* colx = xMat.ptr<float>(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<float>(y,x) = 1-std::abs(colx[x]-colx[x+1])/max;
if(y == 0)
Log(Log::DEBUG)<<xStrech.at<float>(y,x);
cv::Point2f pA(xMat.at<float>(y,x), yMat.at<float>(y,x));
cv::Point2f pB(xMat.at<float>(y,x+1), yMat.at<float>(y,x+1));
cv::Point2f pC(xMat.at<float>(y+1,x), yMat.at<float>(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<float>(y,x) - yMat.at<float>(y+1,x);
if(strech > max)
max = strech;
cv::Point2f pA(xMat.at<float>(y,x), yMat.at<float>(y,x));
cv::Point2f pB(xMat.at<float>(y,x+1), yMat.at<float>(y,x+1));
cv::Point2f pC(xMat.at<float>(y+1,x), yMat.at<float>(y+1,x));
double normX = cv::norm(pA-pB);
double normY = cv::norm(pA-pC);
greatestAngle.at<float>(y,x) = 1-(std::min(normX, normY)/max);
if(y == 0)
Log(Log::DEBUG)<<greatestAngle.at<float>(y,x);
}
for(int y = 0; y < yMat.rows-1; y++)
yStrech.at<float>(y,x) = 1-std::abs(yMat.at<float>(y,x) - yMat.at<float>(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);

View File

@ -25,8 +25,7 @@
struct RemapedImage
{
cv::Mat image;
cv::Mat angleX;
cv::Mat angleY;
cv::Mat angle;
cv::Point2i origin;
};