Improved error detection and reporting and fixed the inlay filter.

This commit is contained in:
Delalande Ivan 2012-07-16 13:11:24 +02:00
parent 327c00ac18
commit cb018be32e
3 changed files with 98 additions and 38 deletions

View File

@ -4,9 +4,9 @@
static inline bool is_inlay(int strict, cv::Vec3b ref, cv::Vec3b pix) static inline bool is_inlay(int strict, cv::Vec3b ref, cv::Vec3b pix)
{ {
return (strict && ref == pix) || (!strict && return (strict && ref == pix) || (!strict &&
((ref[0] > 0 && pix[0] > 127 && pix[0] > pix[1] && pix[0] > pix[2]) ((ref[0] > 0 && pix[0] - pix[1] > 30 && pix[0] - pix[2] > 30)
|| (ref[1] > 0 && pix[1] > 127 && pix[1] > pix[0] && pix[1] > pix[2]) || (ref[1] > 0 && pix[1] - pix[0] > 30 && pix[1] - pix[2] > 30)
|| (ref[2] > 0 && pix[2] > 127 && pix[2] > pix[0] && pix[2] > pix[1]))); || (ref[2] > 0 && pix[2] - pix[0] > 30 && pix[2] - pix[1] > 30)));
} }
void* Inlay::operator()(void* para) void* Inlay::operator()(void* para)

View File

@ -77,6 +77,11 @@ bool parse_cli(Configuration& conf, int argc, char** argv)
for (auto it = vs.begin(); it != vs.end(); ++it) for (auto it = vs.begin(); it != vs.end(); ++it)
conf.input.push_back(std::string(*it)); conf.input.push_back(std::string(*it));
} }
else
{
std::cerr << "Please provide an input file" << std::endl;
return false;
}
if (vm.count("filter")) if (vm.count("filter"))
{ {
@ -111,8 +116,6 @@ int main (int argc, char** argv)
{ {
if (!pipe.add_filter(filter.first, filter.second)) if (!pipe.add_filter(filter.first, filter.second))
{ {
std::cerr << argv[0] << ": Unknown filter `"
<< filter.first << "'" << std::endl;
return 2; return 2;
} }
} }

View File

@ -43,11 +43,19 @@ bool Pipeline::add_filter(std::string filter, std::vector<int> args)
else if (filter == "rotate-v") else if (filter == "rotate-v")
this->pipeline_.add_filter(*(new Rotate(2))); this->pipeline_.add_filter(*(new Rotate(2)));
else if (filter == "color" && args.size() >= 3) else if (filter == "color" && args.size() >= 3)
this->pipeline_.add_filter(*(new Color(cv::Vec3b { {
(unsigned char) args[0], if (args.size() < 3)
(unsigned char) args[1], {
(unsigned char) args[2] std::cerr << "Missing parameters for filter color" << std::endl;
}))); return false;
}
else
this->pipeline_.add_filter(*(new Color(cv::Vec3b {
(unsigned char) args[0],
(unsigned char) args[1],
(unsigned char) args[2]
})));
}
else if (filter == "sepia") else if (filter == "sepia")
{ {
this->pipeline_.add_filter(*(new Grey())); this->pipeline_.add_filter(*(new Grey()));
@ -60,44 +68,93 @@ bool Pipeline::add_filter(std::string filter, std::vector<int> args)
else else
this->pipeline_.add_filter(*(new Blur())); this->pipeline_.add_filter(*(new Blur()));
} }
else if (filter == "merge" && this->input_it_ != this->input_.end()) else if (filter == "merge")
{ {
this->pipeline_.add_filter(*(new Compose(*this->input_it_))); if (this->input_it_ != this->input_.end())
this->input_it_++; {
this->pipeline_.add_filter(*(new Merge())); this->pipeline_.add_filter(*(new Compose(*this->input_it_)));
this->input_it_++;
this->pipeline_.add_filter(*(new Merge()));
}
else
{
std::cerr << "Missing additional input file argument for filter merge"
<< std::endl;
return false;
}
} }
else if (filter == "interlace" && this->input_it_ != this->input_.end()) else if (filter == "interlace")
{ {
this->pipeline_.add_filter(*(new Compose(*this->input_it_))); if (this->input_it_ != this->input_.end())
this->input_it_++; {
this->pipeline_.add_filter(*(new Interlace())); this->pipeline_.add_filter(*(new Compose(*this->input_it_)));
this->input_it_++;
this->pipeline_.add_filter(*(new Interlace()));
}
else
{
std::cerr << "Missing additional input file argument for filter "
"interlace" << std::endl;
return false;
}
} }
else if (filter == "inlay" && this->input_it_ != this->input_.end() else if (filter == "inlay")
&& args.size() >= 3)
{ {
this->pipeline_.add_filter(*(new Compose(*this->input_it_))); if (this->input_it_ == this->input_.end())
this->input_it_++; {
this->pipeline_.add_filter( std::cerr << "Missing additional input file argument for filter inlay"
*(new Inlay(cv::Vec3b { << std::endl;
(unsigned char) args[0], return false;
(unsigned char) args[1], }
(unsigned char) args[2] else if (args.size() < 3)
}, 0))); {
std::cerr << "Missing parameters for filter inlay"
<< std::endl;
return false;
}
else
{
this->pipeline_.add_filter(*(new Compose(*this->input_it_)));
this->input_it_++;
this->pipeline_.add_filter(
*(new Inlay(cv::Vec3b {
(unsigned char) args[0],
(unsigned char) args[1],
(unsigned char) args[2]
}, 0)));
}
} }
else if (filter == "strictinlay" && this->input_it_ != this->input_.end() else if (filter == "strictinlay" && args.size() >= 3)
&& args.size() >= 3)
{ {
this->pipeline_.add_filter(*(new Compose(*this->input_it_))); if (this->input_it_ == this->input_.end())
this->input_it_++; {
this->pipeline_.add_filter( std::cerr << "Missing additional input file argument for filter "
*(new Inlay(cv::Vec3b { "strictinlay" << std::endl;
(unsigned char) args[0], return false;
(unsigned char) args[1], }
(unsigned char) args[2] else if (args.size() < 3)
}, 1))); {
std::cerr << "Missing parameters for filter strictinlay" << std::endl;
return false;
}
else
{
this->pipeline_.add_filter(*(new Compose(*this->input_it_)));
this->input_it_++;
this->pipeline_.add_filter(
*(new Inlay(cv::Vec3b {
(unsigned char) args[0],
(unsigned char) args[1],
(unsigned char) args[2]
}, 1)));
}
} }
else else
{
std::cerr << ": Unknown filter `"
<< filter << "'" << std::endl;
return false; return false;
}
return true; return true;
} }