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)
{
return (strict && ref == pix) || (!strict &&
((ref[0] > 0 && pix[0] > 127 && pix[0] > pix[1] && pix[0] > pix[2])
|| (ref[1] > 0 && pix[1] > 127 && pix[1] > pix[0] && pix[1] > pix[2])
|| (ref[2] > 0 && pix[2] > 127 && pix[2] > pix[0] && pix[2] > pix[1])));
((ref[0] > 0 && pix[0] - pix[1] > 30 && pix[0] - pix[2] > 30)
|| (ref[1] > 0 && pix[1] - pix[0] > 30 && pix[1] - pix[2] > 30)
|| (ref[2] > 0 && pix[2] - pix[0] > 30 && pix[2] - pix[1] > 30)));
}
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)
conf.input.push_back(std::string(*it));
}
else
{
std::cerr << "Please provide an input file" << std::endl;
return false;
}
if (vm.count("filter"))
{
@ -111,8 +116,6 @@ int main (int argc, char** argv)
{
if (!pipe.add_filter(filter.first, filter.second))
{
std::cerr << argv[0] << ": Unknown filter `"
<< filter.first << "'" << std::endl;
return 2;
}
}

View File

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