140 lines
2.8 KiB
C++
140 lines
2.8 KiB
C++
#include <iostream>
|
|
#include <opencv2/highgui.hpp>
|
|
#include <opencv2/core/ocl.hpp>
|
|
#include <unistd.h>
|
|
#include <vector>
|
|
#include <string>
|
|
#include "argpopt.h"
|
|
#include "unwrap.h"
|
|
#include "bgremoval.h"
|
|
#include "normalize.h"
|
|
|
|
void cd_to_exe_dir( char *argv[] )
|
|
{
|
|
std::string path = argv[0];
|
|
int ii = path.length();
|
|
while ( !( path[ii] == '/' || path[ii] == '\\' ) && ii > 0 )
|
|
{
|
|
ii--;
|
|
}
|
|
path.erase( ii, 100 );
|
|
chdir( path.c_str() );
|
|
}
|
|
|
|
std::vector<cv::Mat> loadImages(char** fileNames)
|
|
{
|
|
std::vector<cv::Mat> images;
|
|
for(size_t i = 0; fileNames[i]; ++i)
|
|
{
|
|
cv::Mat tmpImage = cv::imread(fileNames[i]);
|
|
if(tmpImage.data)images.push_back(tmpImage);
|
|
else std::cout<<"can not read image "<<i<<" from "<<fileNames[i]<<'\n';
|
|
}
|
|
return images;
|
|
}
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
cv::ocl::setUseOpenCL(false);
|
|
std::cout<<"UVOS Optical lubricant thikness mapper "<<argp_program_version<<std::endl;
|
|
cd_to_exe_dir(argv);
|
|
|
|
Config config;
|
|
argp_parse(&argp, argc, argv, 0, 0, &config);
|
|
|
|
std::vector<cv::Mat> inImages = loadImages(config.inFileNames);
|
|
|
|
if(inImages.empty())
|
|
{
|
|
std::cout<<"Input images must be provided!\n";
|
|
return -1;
|
|
}
|
|
|
|
if(config.verbose)
|
|
{
|
|
cv::namedWindow( "Viewer", cv::WINDOW_NORMAL );
|
|
cv::resizeWindow("Viewer", 960, 500);
|
|
}
|
|
|
|
|
|
if(config.maps.empty())
|
|
{
|
|
cv::Mat mask;
|
|
if(config.verbose)
|
|
{
|
|
cv::imshow( "Viewer", inImages[0] );
|
|
cv::waitKey(0);
|
|
}
|
|
if(!config.bg.empty())
|
|
{
|
|
cv::Mat bg = cv::imread(config.bg);
|
|
|
|
if(bg.data)
|
|
{
|
|
createMask(inImages[0], mask, bg);
|
|
if(config.verbose)
|
|
{
|
|
cv::Mat masked;
|
|
inImages[0].copyTo(masked, mask);
|
|
cv::imshow( "Viewer", masked );
|
|
cv::waitKey(0);
|
|
}
|
|
}
|
|
else std::cout<<"can not read background image from "<<config.bg<<'\n';
|
|
}
|
|
createRemapMap(inImages[0], config.inFileNames[0], mask, config.verbose);
|
|
}
|
|
else
|
|
{
|
|
cv::FileStorage fs(config.maps, cv::FileStorage::READ);
|
|
if (!fs.isOpened())
|
|
{
|
|
std::cerr<<"could not open maps file " <<config.maps<<'\n';
|
|
return -1;
|
|
}
|
|
cv::Mat xMat;
|
|
cv::Mat yMat;
|
|
fs["xmat"]>>xMat;
|
|
fs["ymat"]>>yMat;
|
|
|
|
cv::Mat norm;
|
|
if(!config.norm.empty())
|
|
{
|
|
cv::Mat tmp = cv::imread(config.norm);
|
|
if(!tmp.data)
|
|
{
|
|
std::cerr<<"could not open normalize file " <<config.norm<<'\n';
|
|
}
|
|
applyRemap(tmp, norm, xMat, yMat, cv::Size(900,1000));
|
|
if(config.verbose)
|
|
{
|
|
cv::imshow("Viewer", norm );
|
|
cv::waitKey(0);
|
|
}
|
|
}
|
|
|
|
for(auto& image : inImages)
|
|
{
|
|
if(config.verbose)
|
|
{
|
|
cv::imshow( "Viewer", image );
|
|
cv::waitKey(0);
|
|
}
|
|
cv::Mat remaped;
|
|
applyRemap(image, remaped, xMat, yMat, cv::Size(900,1000));
|
|
if(norm.data) normalize(remaped, norm);
|
|
cv::imshow( "Viewer", remaped );
|
|
cv::waitKey(0);
|
|
}
|
|
}
|
|
|
|
if(config.verbose)
|
|
{
|
|
cv::destroyWindow("Viewer");
|
|
cv::waitKey(0);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|