add show image operation

This commit is contained in:
2021-07-05 11:26:23 +02:00
parent f3d2a19781
commit 6fa7e9eb9d
5 changed files with 70 additions and 36 deletions

View File

@ -42,6 +42,7 @@ enum {
APPLY_MAP,
APPLY_CURVE,
CREATE_CURVE,
SHOW_IMAGE,
EXIT
};
@ -59,6 +60,8 @@ int selectOperation(char** opt)
return CREATE_CURVE;
else if(strcmp(opt[0], "mkboard" ) == 0)
return CREATE_CHARUCO;
else if(strcmp(opt[0], "show" ) == 0)
return SHOW_IMAGE;
else if(strcmp(opt[0], "exit" ) == 0)
return EXIT;
return -1;
@ -115,13 +118,19 @@ std::vector<cv::Mat> loadImages(char** fileNames)
cv::Mat tmpImage;
const std::string str(fileNames[i]);
if(str.find(".mat") != std::string::npos)
openImageYml(fileNames[i]);
else
tmpImage = openImageImg(fileNames[i]);
{
Log(Log::DEBUG)<<__func__<<": "<<fileNames[i]<<" as YAML image";
tmpImage = openImageYml(fileNames[i]);
}
else
{
Log(Log::DEBUG)<<__func__<<": "<<fileNames[i]<<" as png image";
tmpImage = openImageImg(fileNames[i]);
}
if(tmpImage.data)
images.push_back(tmpImage);
else
Log(Log::WARN)<<"can not read image "<<i<<" from "<<fileNames[i]<<'\n';
Log(Log::WARN)<<"can not read image "<<i<<" from "<<fileNames[i];
}
return images;
}
@ -129,7 +138,7 @@ std::vector<cv::Mat> loadImages(char** fileNames)
int perfromOperation(int operation, char** fileNames, const Config& config)
{
std::vector<cv::Mat> inImages;
if(operation == CREATE_MAP || operation == APPLY_MAP || operation == APPLY_CURVE)
if(operation == CREATE_MAP || operation == APPLY_MAP || operation == APPLY_CURVE || operation == SHOW_IMAGE)
{
inImages = loadImages(fileNames);
@ -323,6 +332,16 @@ int perfromOperation(int operation, char** fileNames, const Config& config)
std::cout<<"Curve saved to "<<(!config.output.empty() ? config.output : "curve.mat")<<'\n';
}
else if(operation == SHOW_IMAGE)
{
cv::namedWindow("Show Image", cv::WINDOW_NORMAL );
for(size_t i = 0; i < inImages.size(); ++i)
{
cv::imshow("Show Image", inImages[i]);
cv::waitKey(0);
}
cv::destroyWindow("Show Image");
}
else if(operation == EXIT)
return -1;
return 0;