#include <IPSDKCore/Config/LibraryInitializer.h>
#include <IPSDKImageFile/Logger/IPSDKImageFileException.h>
#include <IPSDKBaseShapeSegmentation/Entity/2d/Shape2dColl.h>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/program_options/cmdline.hpp>
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp>
#include <log4cplus/consoleappender.h>
#include <iostream>
#include <fstream>
bool
boost::filesystem::path& inImgFilePath,
std::vector<boost::filesystem::path>& vInTemplateImgFilePath,
boost::filesystem::path& outImgFilePath,
boost::filesystem::path& outputCsvResultPath,
{
std::ofstream file(fileName.c_str(), std::ios::out | std::ios::trunc);
if (!file)
return false;
file << "Shape Index;Matched Template Index; Distance\n";
for (
ipUInt32 i = 0; i < nbTemplates; i++) {
file << (i + 1) << ";";
else
file << "Bad match according to threshold ( = " << threshold << ")";
}
file.close();
return true;
}
int
main(
int argc,
char* argv[])
{
log4cplus::SharedAppenderPtr pConsole(new log4cplus::ConsoleAppender);
log4cplus::Logger::getRoot().addAppender(pConsole);
log4cplus::Logger::getRoot().setLogLevel(log4cplus::INFO_LOG_LEVEL);
case ipsdk::core::eLibInitStatus::eLIS_Warn:
break;
case ipsdk::core::eLibInitStatus::eLIS_Failed:
return -1;
break;
default:
break;
}
boost::filesystem::path inImgFilePath, outImgFilePath, outputCsvResultPath;
std::vector<boost::filesystem::path> vInTemplateImgFilePath;
ipReal64 thresholdDistance, thresholdBinarization;
if (!
readCmdArguments(argc, argv, inImgFilePath, vInTemplateImgFilePath, outImgFilePath, outputCsvResultPath, thresholdBinarization, thresholdDistance, stdDev))
return -1;
% inImgFilePath.string());
try {
}
% inImgFilePath.string() % e.
getMsg());
return -1;
}
% inImgFilePath.string());
const ipUInt32 nbTemplates =
static_cast<ipUInt32>(vInTemplateImgFilePath.size());
std::vector<ipsdk::image::ImagePtr> vTemplateImg;
vTemplateImg.resize(nbTemplates);
for (
ipUInt32 i = 0; i < nbTemplates; ++i) {
try {
}
% vInTemplateImgFilePath[i].
string() % e.
getMsg());
return -1;
}
}
if (stdDev > 0.f)
if (stdDev > 0.f) {
try {
}
return -1;
}
}
std::vector<Shape2dCollPtr> vTemplateShape2dCollPtr;
try {
for (
ipUInt32 i = 0; i < nbTemplates; ++i) {
vTemplateShape2dCollPtr.push_back(pShape2dColl_template);
}
}
return -1;
}
std::vector<ipsdk::geom::MatchShapesInfo> vMatches;
vMatches.resize(nbTemplates);
for (
ipUInt32 templateIdx = 0; templateIdx < nbTemplates; ++templateIdx) {
vMatches[templateIdx] = matches;
}
for (
ipUInt32 shapeIdx = 0; shapeIdx < nbShapes; ++shapeIdx) {
for (
ipUInt32 templateIdx = 0; templateIdx < nbTemplates; ++templateIdx) {
}
}
}
pLut->setValue<ipsdk::imaproc::attr::IntensityLUT::BinWidth>(1.0);
pLut->setValue<ipsdk::imaproc::attr::IntensityLUT::InMin>(.0);
pLut->push_back<ipsdk::imaproc::attr::IntensityLUT::LookupTable>(0);
const ipUInt32 nbLabels = pShape2dColl->getSize();
for (
ipUInt32 i = 1; i < nbLabels; ++i) {
pLut->push_back<ipsdk::imaproc::attr::IntensityLUT::LookupTable>(matchIndex);
else
pLut->push_back<ipsdk::imaproc::attr::IntensityLUT::LookupTable>(0);
}
try {
}
return -1;
}
ipBool bWritten = writeToCsvFile(outputCsvResultPath, bestMatches, thresholdDistance);
if (bWritten == false) {
return -1;
}
return 0;
}
bool
boost::filesystem::path& inImgFilePath,
std::vector<boost::filesystem::path>& vInTemplateImgFilePath,
boost::filesystem::path& outImgFilePath,
boost::filesystem::path& outputCsvResultPath,
{
boost::program_options::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("inputImgFilePath", value<path>(),
"input image file path (optional; only TIFF format is accepted)")
("inTemplatePathList", boost::program_options::value< std::vector<boost::filesystem::path> >()->multitoken(),
"list of input template image file path (optional; only TIFF format is accepted)")
("inThresholdBinarization", value<ipReal64>(),
"input binarization used for shape extraction (optional; default value = 15)")
("inThresholdDistance", value<ipReal64>(),
"input shape distance threshold (optional; default value = 0.2)")
("inStdDev", value<ipReal32>(),
"standard deviation for Gaussian smoothing, used to blur the edges (optional; default value = 1)")
("outputImgFilePath", value<path>(),
"output image file path (optional; only TIFF format is accepted)")
("outputCsvResultPath", value<path>(),
"output CSV file path (optional; the file is named shapeMatches.csv and is located in the same directory thant the output image path if not specified)")
;
boost::program_options::variables_map vm;
try {
boost::program_options::store(parse_command_line(argc, argv, desc), vm);
}
catch (const std::exception& e) {
% e.what());
return false;
}
boost::program_options::notify(vm);
if (vm.count("help")) {
std::cout << desc << "\n";
return false;
}
if (vm.count("inputImgFilePath")) {
inImgFilePath = vm["inputImgFilePath"].as<path>();
}
if (!boost::filesystem::exists(inImgFilePath)) {
% inImgFilePath);
return false;
}
if (vm.count("inTemplatePathList")) {
vInTemplateImgFilePath = vm["inTemplatePathList"].as< std::vector<boost::filesystem::path> >();
}
else {
vInTemplateImgFilePath.clear();
vInTemplateImgFilePath.push_back(
getIPSDKDirectory(eInternalDirectory::eID_Images) /
"Templates/templateSquare.tif");
vInTemplateImgFilePath.push_back(
getIPSDKDirectory(eInternalDirectory::eID_Images) /
"Templates/templateTriangle.tif");
vInTemplateImgFilePath.push_back(
getIPSDKDirectory(eInternalDirectory::eID_Images) /
"Templates/templateHexagon.tif");
vInTemplateImgFilePath.push_back(
getIPSDKDirectory(eInternalDirectory::eID_Images) /
"Templates/templateCircle.tif");
}
if (vm.count("outputImgFilePath"))
outImgFilePath = vm["outputImgFilePath"].as<path>();
else {
const path outputDir =
"Sample";
if (!boost::filesystem::exists(outputDir)) {
try {
boost::filesystem::create_directories(outputDir);
}
catch (const std::exception& e) {
% outputDir % e.what());
}
}
outImgFilePath = outputDir / "shapeMatch.tif";
}
if (vm.count("outputCsvResultPath"))
outputCsvResultPath = vm["outputCsvResultPath"].as<path>();
else {
const path outputDir = outImgFilePath.parent_path();
outputCsvResultPath = outputDir / "shapeMatch.csv";
}
if (vm.count("inThresholdBinarization")) {
thresholdBinarization = vm[
"inThresholdBinarization"].as<
ipReal64>();
}
else thresholdBinarization = 15;
if (vm.count("inThresholdDistance")) {
thresholdDistance = vm[
"inThresholdDistance"].as<
ipReal64>();
}
else thresholdDistance = 0.2;
if (vm.count("inStdDev")) {
}
return true;
}