Added a greyscale filter to test that filters really work.

This commit is contained in:
Delalande Ivan 2012-07-13 00:03:02 +02:00
parent 335832789a
commit 875745cf22
10 changed files with 50 additions and 9 deletions

View File

@ -1,3 +1,4 @@
#include "opencv2/opencv.hpp"
#include "video_reader.hh" #include "video_reader.hh"
VideoReader::VideoReader(const VideoReader& vr) VideoReader::VideoReader(const VideoReader& vr)

View File

@ -3,7 +3,6 @@
# include <string> # include <string>
# include "tbb/pipeline.h" # include "tbb/pipeline.h"
# include "video.hh"
class VideoReader: public tbb::filter class VideoReader: public tbb::filter
{ {

View File

@ -1,3 +1,4 @@
#include "opencv2/opencv.hpp"
#include "video_writer.hh" #include "video_writer.hh"
VideoWriter::VideoWriter(const VideoWriter& vw) VideoWriter::VideoWriter(const VideoWriter& vw)

View File

@ -3,7 +3,6 @@
# include <string> # include <string>
# include "tbb/pipeline.h" # include "tbb/pipeline.h"
# include "video.hh"
class VideoWriter: public tbb::filter class VideoWriter: public tbb::filter
{ {

View File

@ -6,4 +6,4 @@ AM_CXXFLAGS = \
$(BOOST_CPPFLAGS) \ $(BOOST_CPPFLAGS) \
$(DEBUG_CXXFLAGS) $(DEBUG_CXXFLAGS)
______lib_libfilterSample_a_SOURCES = ______lib_libfilterSample_a_SOURCES = grey.cc

19
src/filterSample/grey.cc Normal file
View File

@ -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;
}

13
src/filterSample/grey.hh Normal file
View File

@ -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_ */

View File

@ -7,7 +7,6 @@
#include "configuration.hh" #include "configuration.hh"
#include "pipeline.hh" #include "pipeline.hh"
#include "encoder/video.hh"
#include "encoder/video_reader.hh" #include "encoder/video_reader.hh"
#include "encoder/video_writer.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()); vw.open(conf.output, conf.codec, vr.fps_get(), vr.width_get(), vr.height_get());
Pipeline pipe(std::list<VideoReader> { vr }, vw); Pipeline pipe(std::list<VideoReader> { vr }, vw);
// add filters // add filters here
pipe.add_filter("grey");
pipe.run(); pipe.run();
return 0; return 0;

View File

@ -1,9 +1,21 @@
#include "tbb/pipeline.h" #include "tbb/pipeline.h"
#include "pipeline.hh" #include "pipeline.hh"
#include "filterSample/grey.hh"
Pipeline::Pipeline(std::list<VideoReader> input, VideoWriter output)
: input_(input), output_(output)
{
this->pipeline_.add_filter(this->input_.front());
}
bool Pipeline::add_filter(std::string filter) bool Pipeline::add_filter(std::string filter)
{ {
if (filter == "grey" || filter == "gray")
this->pipeline_.add_filter(*(new Grey()));
else
return false;
return true; return true;
} }
@ -16,8 +28,6 @@ void Pipeline::run()
for (auto it = this->input_.begin(); it != this->input_.end(); ++it) for (auto it = this->input_.begin(); it != this->input_.end(); ++it)
it->maxframe_set(minframe); it->maxframe_set(minframe);
this->pipeline_.add_filter(this->input_.front());
this->pipeline_.add_filter(this->output_); this->pipeline_.add_filter(this->output_);
this->pipeline_.run(CHUNK_SIZE); this->pipeline_.run(CHUNK_SIZE);
} }

View File

@ -14,8 +14,7 @@
class Pipeline class Pipeline
{ {
public: public:
Pipeline(std::list<VideoReader> input, VideoWriter output) Pipeline(std::list<VideoReader> input, VideoWriter output);
: input_(input), output_(output) {}
bool add_filter(std::string filter); bool add_filter(std::string filter);
void run(); void run();
private: private: