From 875745cf224b6acf8190f4a962869e3fdeac2f20 Mon Sep 17 00:00:00 2001 From: Delalande Ivan Date: Fri, 13 Jul 2012 00:03:02 +0200 Subject: [PATCH] Added a greyscale filter to test that filters really work. --- src/encoder/video_reader.cc | 1 + src/encoder/video_reader.hh | 1 - src/encoder/video_writer.cc | 1 + src/encoder/video_writer.hh | 1 - src/filterSample/Makefile.am | 2 +- src/filterSample/grey.cc | 19 +++++++++++++++++++ src/filterSample/grey.hh | 13 +++++++++++++ src/main.cc | 4 ++-- src/pipeline.cc | 14 ++++++++++++-- src/pipeline.hh | 3 +-- 10 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 src/filterSample/grey.cc create mode 100644 src/filterSample/grey.hh diff --git a/src/encoder/video_reader.cc b/src/encoder/video_reader.cc index 80f3616..2153943 100644 --- a/src/encoder/video_reader.cc +++ b/src/encoder/video_reader.cc @@ -1,3 +1,4 @@ +#include "opencv2/opencv.hpp" #include "video_reader.hh" VideoReader::VideoReader(const VideoReader& vr) diff --git a/src/encoder/video_reader.hh b/src/encoder/video_reader.hh index 9899643..490481b 100644 --- a/src/encoder/video_reader.hh +++ b/src/encoder/video_reader.hh @@ -3,7 +3,6 @@ # include # include "tbb/pipeline.h" -# include "video.hh" class VideoReader: public tbb::filter { diff --git a/src/encoder/video_writer.cc b/src/encoder/video_writer.cc index 1e62853..79c2c9a 100644 --- a/src/encoder/video_writer.cc +++ b/src/encoder/video_writer.cc @@ -1,3 +1,4 @@ +#include "opencv2/opencv.hpp" #include "video_writer.hh" VideoWriter::VideoWriter(const VideoWriter& vw) diff --git a/src/encoder/video_writer.hh b/src/encoder/video_writer.hh index dc9cf2d..793769c 100644 --- a/src/encoder/video_writer.hh +++ b/src/encoder/video_writer.hh @@ -3,7 +3,6 @@ # include # include "tbb/pipeline.h" -# include "video.hh" class VideoWriter: public tbb::filter { diff --git a/src/filterSample/Makefile.am b/src/filterSample/Makefile.am index a8a337e..3d4787d 100644 --- a/src/filterSample/Makefile.am +++ b/src/filterSample/Makefile.am @@ -6,4 +6,4 @@ AM_CXXFLAGS = \ $(BOOST_CPPFLAGS) \ $(DEBUG_CXXFLAGS) -______lib_libfilterSample_a_SOURCES = +______lib_libfilterSample_a_SOURCES = grey.cc diff --git a/src/filterSample/grey.cc b/src/filterSample/grey.cc new file mode 100644 index 0000000..779e13c --- /dev/null +++ b/src/filterSample/grey.cc @@ -0,0 +1,19 @@ +#include "grey.hh" +#include "opencv2/opencv.hpp" + +void* Grey::operator()(void* para) +{ + cv::Mat* mat = (cv::Mat*)para; + + if (mat == nullptr) + return nullptr; + + /* + ** RGB2GRAY convert to a black&white matrix that the videowriter refuse, we + ** have to convert it back to RGB. + */ + cv::cvtColor(*mat, *mat, CV_RGB2GRAY); + cv::cvtColor(*mat, *mat, CV_GRAY2RGB); + + return mat; +} diff --git a/src/filterSample/grey.hh b/src/filterSample/grey.hh new file mode 100644 index 0000000..91b1bcd --- /dev/null +++ b/src/filterSample/grey.hh @@ -0,0 +1,13 @@ +#ifndef GREY_HH_ +# define GREY_HH_ + +# include "tbb/pipeline.h" + +class Grey: public tbb::filter +{ + public: + Grey(): filter(tbb::filter::parallel) {} + void* operator()(void*); +}; + +#endif /* !GREY_HH_ */ diff --git a/src/main.cc b/src/main.cc index df87518..b0ebdff 100644 --- a/src/main.cc +++ b/src/main.cc @@ -7,7 +7,6 @@ #include "configuration.hh" #include "pipeline.hh" -#include "encoder/video.hh" #include "encoder/video_reader.hh" #include "encoder/video_writer.hh" @@ -100,7 +99,8 @@ int main (int argc, char** argv) vw.open(conf.output, conf.codec, vr.fps_get(), vr.width_get(), vr.height_get()); Pipeline pipe(std::list { vr }, vw); - // add filters + // add filters here + pipe.add_filter("grey"); pipe.run(); return 0; diff --git a/src/pipeline.cc b/src/pipeline.cc index ec6e943..28c05d1 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -1,9 +1,21 @@ #include "tbb/pipeline.h" #include "pipeline.hh" +#include "filterSample/grey.hh" + +Pipeline::Pipeline(std::list input, VideoWriter output) + : input_(input), output_(output) +{ + this->pipeline_.add_filter(this->input_.front()); +} bool Pipeline::add_filter(std::string filter) { + if (filter == "grey" || filter == "gray") + this->pipeline_.add_filter(*(new Grey())); + else + return false; + return true; } @@ -16,8 +28,6 @@ void Pipeline::run() for (auto it = this->input_.begin(); it != this->input_.end(); ++it) it->maxframe_set(minframe); - this->pipeline_.add_filter(this->input_.front()); this->pipeline_.add_filter(this->output_); - this->pipeline_.run(CHUNK_SIZE); } diff --git a/src/pipeline.hh b/src/pipeline.hh index 9f11ba7..c4e94da 100644 --- a/src/pipeline.hh +++ b/src/pipeline.hh @@ -14,8 +14,7 @@ class Pipeline { public: - Pipeline(std::list input, VideoWriter output) - : input_(input), output_(output) {} + Pipeline(std::list input, VideoWriter output); bool add_filter(std::string filter); void run(); private: