Added a drunk filter and wrote the README.

This commit is contained in:
Delalande Ivan 2012-07-16 12:16:19 +02:00
parent 59d0764071
commit 327c00ac18
6 changed files with 121 additions and 3 deletions

View file

@ -8,4 +8,4 @@ AM_CXXFLAGS = \
______lib_libfilterSample_a_SOURCES = grey.cc reverse.cc merge.cc \
interlace.cc inlay.cc blur.cc cartoon.cc count.cc color.cc \
rotate.cc
rotate.cc drunk.cc

33
src/filterSample/drunk.cc Normal file
View file

@ -0,0 +1,33 @@
#include "drunk.hh"
#include "opencv2/opencv.hpp"
void* Drunk::operator()(void* para)
{
cv::Mat* mat = (cv::Mat*)para;
if (mat == nullptr)
return nullptr;
if (this->last_ == nullptr)
{
this->last_ = new cv::Mat();
*this->last_ = mat->clone();
}
auto it1 = mat->begin<cv::Vec3b>();
auto it2 = this->last_->begin<cv::Vec3b>();
while (it1 != mat->end<cv::Vec3b>() && it2 != this->last_->end<cv::Vec3b>())
{
(*it2)[0] = (*it1)[0] / 8 + (*it2)[0] * 7 / 8;
(*it2)[1] = (*it1)[1] / 8 + (*it2)[1] * 7 / 8;
(*it2)[2] = (*it1)[2] / 8 + (*it2)[2] * 7 / 8;
(*it1)[0] = (*it2)[0];
(*it1)[1] = (*it2)[1];
(*it1)[2] = (*it2)[2];
++it1;
++it2;
}
return mat;
}

16
src/filterSample/drunk.hh Normal file
View file

@ -0,0 +1,16 @@
#ifndef DRUNK_HH_
# define DRUNK_HH_
# include "tbb/pipeline.h"
# include "opencv2/opencv.hpp"
class Drunk: public tbb::filter
{
public:
Drunk(): filter(tbb::filter::parallel), last_(nullptr) {}
void* operator()(void*);
private:
cv::Mat* last_;
};
#endif /* !DRUNK_HH_ */

View file

@ -19,8 +19,8 @@ bool parse_cli(Configuration& conf, int argc, char** argv)
desc.add_options()
("help,h", "produce help message")
("filter,f", po::value<std::vector<std::string>>(), "apply a filter; "
"choose between grey, reverse, cartoon, count, color=B,G,R, sepia, "
"blur[=X], merge, interlace, inlay=B,G,R, strictinlay=B,G,R")
"choose between grey, reverse, cartoon, drunk, count, color=B,G,R, sepia,"
" blur[=X], merge, interlace, inlay=B,G,R, strictinlay=B,G,R")
("input-file,i", po::value<std::vector<std::string>>(), "file to treat")
("output,o", po::value<std::string>(), "output file")
("codec,c", po::value<std::string>(), "output codec")

View file

@ -16,6 +16,7 @@
#include "filterSample/count.hh"
#include "filterSample/color.hh"
#include "filterSample/rotate.hh"
#include "filterSample/drunk.hh"
Pipeline::Pipeline(std::list<VideoReader> input, VideoWriter output)
: input_(input), output_(output)
@ -35,6 +36,8 @@ bool Pipeline::add_filter(std::string filter, std::vector<int> args)
this->pipeline_.add_filter(*(new Cartoon()));
else if (filter == "count")
this->pipeline_.add_filter(*(new Count()));
else if (filter == "drunk")
this->pipeline_.add_filter(*(new Drunk()));
else if (filter == "rotate-h")
this->pipeline_.add_filter(*(new Rotate(0)));
else if (filter == "rotate-v")