add support for kfactor
This commit is contained in:
12
src/main.cpp
12
src/main.cpp
@ -211,7 +211,10 @@ int perfromOperation(int operation, char** fileNames, const Config& config)
|
|||||||
map.outputCellSize = config.size;
|
map.outputCellSize = config.size;
|
||||||
|
|
||||||
if(!map.xMat.data)
|
if(!map.xMat.data)
|
||||||
|
{
|
||||||
|
Log(Log::ERROR)<<"could not load remap map from "<<std::string(fileNames[i])+".mat";
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
RemapedImage norm;
|
RemapedImage norm;
|
||||||
if(!config.norm.empty())
|
if(!config.norm.empty())
|
||||||
@ -219,7 +222,7 @@ int perfromOperation(int operation, char** fileNames, const Config& config)
|
|||||||
cv::Mat tmp = cv::imread(config.norm);
|
cv::Mat tmp = cv::imread(config.norm);
|
||||||
if(!tmp.data)
|
if(!tmp.data)
|
||||||
{
|
{
|
||||||
Log(Log::WARN)<<"could not open normalize file " <<config.norm;
|
Log(Log::WARN)<<"could not open normalize file "<<config.norm;
|
||||||
}
|
}
|
||||||
norm = applyRemap(tmp, map);
|
norm = applyRemap(tmp, map);
|
||||||
if(config.verbose)
|
if(config.verbose)
|
||||||
@ -239,6 +242,13 @@ int perfromOperation(int operation, char** fileNames, const Config& config)
|
|||||||
{
|
{
|
||||||
cv::imshow( "Viewer", remaped.image );
|
cv::imshow( "Viewer", remaped.image );
|
||||||
cv::waitKey(0);
|
cv::waitKey(0);
|
||||||
|
cv::imshow( "Viewer", remaped.angleX);
|
||||||
|
cv::waitKey(0);
|
||||||
|
cv::imshow( "Viewer", remaped.angleY);
|
||||||
|
cv::waitKey(0);
|
||||||
|
applyKfactor(remaped.image, remaped.angleX, 3);
|
||||||
|
cv::imshow( "remaped.image", remaped.image );
|
||||||
|
cv::waitKey(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
remapedImages.push_back(remaped);
|
remapedImages.push_back(remaped);
|
||||||
|
@ -157,17 +157,83 @@ RemapMap loadRemapMap(const std::string& fileName)
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void applyKfactor(cv::Mat& image, const cv::Mat& angleMat, float kFactor)
|
||||||
|
{
|
||||||
|
assert(image.type() == CV_8UC1 && angleMat.type() == CV_32FC1);
|
||||||
|
for(int y = 0; y < image.rows; y++)
|
||||||
|
{
|
||||||
|
uint8_t* colx = image.ptr<uint8_t>(y);
|
||||||
|
const float* anglex = angleMat.ptr<float>(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<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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int x = 0; x < yMat.cols; x++)
|
||||||
|
{
|
||||||
|
float max = 0;
|
||||||
|
for(int y = 0; y < yMat.rows-1; y++)
|
||||||
|
{
|
||||||
|
float strech = yMat.at<float>(y,x) - yMat.at<float>(y+1,x);
|
||||||
|
if(strech > max)
|
||||||
|
max = strech;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RemapedImage applyRemap(const cv::Mat& image, const RemapMap &map)
|
RemapedImage applyRemap(const cv::Mat& image, const RemapMap &map)
|
||||||
{
|
{
|
||||||
RemapedImage out;
|
RemapedImage out;
|
||||||
cv::Mat xMapResized;
|
cv::Mat xMapResized;
|
||||||
cv::Mat yMapResized;
|
cv::Mat yMapResized;
|
||||||
const cv::Size outputSize(map.outputCellSize*map.xMat.cols,map.outputCellSize*map.xMat.rows);
|
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.xMat, xMapResized, outputSize, cv::INTER_LINEAR);
|
||||||
cv::resize(map.yMat, yMapResized, 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 xMapRed = xMapResized(noBorderRoi);
|
||||||
cv::Mat yMapRed = yMapResized(noBorderRoi);
|
cv::Mat yMapRed = yMapResized(noBorderRoi);
|
||||||
cv::remap(image, out.image, xMapRed, yMapRed, cv::INTER_LINEAR);
|
cv::remap(image, out.image, xMapRed, yMapRed, cv::INTER_LINEAR);
|
||||||
|
@ -25,6 +25,8 @@
|
|||||||
struct RemapedImage
|
struct RemapedImage
|
||||||
{
|
{
|
||||||
cv::Mat image;
|
cv::Mat image;
|
||||||
|
cv::Mat angleX;
|
||||||
|
cv::Mat angleY;
|
||||||
cv::Point2i origin;
|
cv::Point2i origin;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -44,5 +46,7 @@ bool createRemapMap(const cv::Mat& image, RemapMap& out, const std::vector<Detec
|
|||||||
|
|
||||||
RemapedImage applyRemap(const cv::Mat& image, const RemapMap &map);
|
RemapedImage applyRemap(const cv::Mat& image, const RemapMap &map);
|
||||||
|
|
||||||
|
void applyKfactor(cv::Mat& image ,const cv::Mat& angleMat, float kFactor);
|
||||||
|
|
||||||
cv::Mat stich(std::vector<RemapedImage>& images, bool seamAdjust = false);
|
cv::Mat stich(std::vector<RemapedImage>& images, bool seamAdjust = false);
|
||||||
cv::Mat simpleStich(const std::vector<RemapedImage>& images);
|
cv::Mat simpleStich(const std::vector<RemapedImage>& images);
|
||||||
|
Reference in New Issue
Block a user