New filters: rotate-h and rotate-v
This commit is contained in:
parent
b6b2e9c24f
commit
59d0764071
@ -7,7 +7,7 @@ Configuration::add_filter(const std::string param)
|
||||
{
|
||||
std::pair<std::string, std::vector<int> > pair;
|
||||
|
||||
boost::char_separator<char> sep(",-;|. =");
|
||||
boost::char_separator<char> sep(",;:. =");
|
||||
boost::tokenizer<boost::char_separator<char> > tokens(param, sep);
|
||||
|
||||
for (auto tok : tokens)
|
||||
|
@ -7,4 +7,5 @@ AM_CXXFLAGS = \
|
||||
$(DEBUG_CXXFLAGS)
|
||||
|
||||
______lib_libfilterSample_a_SOURCES = grey.cc reverse.cc merge.cc \
|
||||
interlace.cc inlay.cc blur.cc cartoon.cc count.cc color.cc
|
||||
interlace.cc inlay.cc blur.cc cartoon.cc count.cc color.cc \
|
||||
rotate.cc
|
||||
|
@ -11,9 +11,14 @@ void* Color::operator()(void* para)
|
||||
for (size_t i = 0; i < mat->rows; ++i)
|
||||
for (size_t j = 0; j < mat->cols; ++j)
|
||||
{
|
||||
mat->at<cv::Vec3b>(i, j)[0] = mat->at<cv::Vec3b>(i, j)[0] * this->ref_[0] / 255;
|
||||
mat->at<cv::Vec3b>(i, j)[1] = mat->at<cv::Vec3b>(i, j)[1] * this->ref_[1] / 255;
|
||||
mat->at<cv::Vec3b>(i, j)[2] = mat->at<cv::Vec3b>(i, j)[2] * this->ref_[2] / 255;
|
||||
mat->at<cv::Vec3b>(i, j)[0] = mat->at<cv::Vec3b>(i, j)[0]
|
||||
* this->ref_[0] / 255;
|
||||
|
||||
mat->at<cv::Vec3b>(i, j)[1] = mat->at<cv::Vec3b>(i, j)[1]
|
||||
* this->ref_[1] / 255;
|
||||
|
||||
mat->at<cv::Vec3b>(i, j)[2] = mat->at<cv::Vec3b>(i, j)[2]
|
||||
* this->ref_[2] / 255;
|
||||
}
|
||||
|
||||
return mat;
|
||||
|
29
src/filterSample/rotate.cc
Normal file
29
src/filterSample/rotate.cc
Normal file
@ -0,0 +1,29 @@
|
||||
#include "rotate.hh"
|
||||
|
||||
void* Rotate::operator()(void* para)
|
||||
{
|
||||
cv::Mat* mat = (cv::Mat*)para;
|
||||
|
||||
if (mat == nullptr)
|
||||
return nullptr;
|
||||
|
||||
if (direction_ == 0) // rotate-h
|
||||
for (size_t i = 0; i < mat->rows; ++i)
|
||||
for (size_t j = mat->cols / 2 + 1; j > 0; --j)
|
||||
{
|
||||
cv::Vec3b tmp = mat->at<cv::Vec3b>(i, j);
|
||||
mat->at<cv::Vec3b>(i, j) = mat->at<cv::Vec3b>(i, mat->cols - j - 1);
|
||||
mat->at<cv::Vec3b>(i, mat->cols - j - 1) = tmp;
|
||||
}
|
||||
|
||||
else if (direction_ == 2 || direction_ == -2) // rotate-v
|
||||
for (size_t i = mat->rows / 2 + 1; i > 0; --i)
|
||||
for (size_t j = 0; j < mat->cols; ++j)
|
||||
{
|
||||
cv::Vec3b tmp = mat->at<cv::Vec3b>(i, j);
|
||||
mat->at<cv::Vec3b>(i, j) = mat->at<cv::Vec3b>(mat->rows - i - 1, j);
|
||||
mat->at<cv::Vec3b>(mat->rows - i - 1, j) = tmp;
|
||||
}
|
||||
|
||||
return mat;
|
||||
}
|
17
src/filterSample/rotate.hh
Normal file
17
src/filterSample/rotate.hh
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef ROTATE_HH_
|
||||
# define ROTATE_HH_
|
||||
|
||||
# include "tbb/pipeline.h"
|
||||
# include "opencv2/opencv.hpp"
|
||||
|
||||
class Rotate: public tbb::filter
|
||||
{
|
||||
public:
|
||||
Rotate(char direction)
|
||||
: filter(tbb::filter::parallel), direction_(direction) {}
|
||||
void* operator()(void*);
|
||||
private:
|
||||
char direction_;
|
||||
};
|
||||
|
||||
#endif /* !ROTATE_HH_ */
|
@ -18,7 +18,9 @@ bool parse_cli(Configuration& conf, int argc, char** argv)
|
||||
po::options_description desc("Allowed options");
|
||||
desc.add_options()
|
||||
("help,h", "produce help message")
|
||||
("filter,f", po::value<std::vector<std::string>>(), "apply a filter")
|
||||
("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")
|
||||
("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")
|
||||
@ -110,7 +112,7 @@ int main (int argc, char** argv)
|
||||
if (!pipe.add_filter(filter.first, filter.second))
|
||||
{
|
||||
std::cerr << argv[0] << ": Unknown filter `"
|
||||
<< filter.first << "'" << filter.second.size() << std::endl;
|
||||
<< filter.first << "'" << std::endl;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "filterSample/inlay.hh"
|
||||
#include "filterSample/count.hh"
|
||||
#include "filterSample/color.hh"
|
||||
#include "filterSample/rotate.hh"
|
||||
|
||||
Pipeline::Pipeline(std::list<VideoReader> input, VideoWriter output)
|
||||
: input_(input), output_(output)
|
||||
@ -34,6 +35,10 @@ 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 == "rotate-h")
|
||||
this->pipeline_.add_filter(*(new Rotate(0)));
|
||||
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],
|
||||
|
Reference in New Issue
Block a user