Added a greyscale filter to test that filters really work.
This commit is contained in:
parent
335832789a
commit
875745cf22
@ -1,3 +1,4 @@
|
||||
#include "opencv2/opencv.hpp"
|
||||
#include "video_reader.hh"
|
||||
|
||||
VideoReader::VideoReader(const VideoReader& vr)
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
# include <string>
|
||||
# include "tbb/pipeline.h"
|
||||
# include "video.hh"
|
||||
|
||||
class VideoReader: public tbb::filter
|
||||
{
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include "opencv2/opencv.hpp"
|
||||
#include "video_writer.hh"
|
||||
|
||||
VideoWriter::VideoWriter(const VideoWriter& vw)
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
# include <string>
|
||||
# include "tbb/pipeline.h"
|
||||
# include "video.hh"
|
||||
|
||||
class VideoWriter: public tbb::filter
|
||||
{
|
||||
|
@ -6,4 +6,4 @@ AM_CXXFLAGS = \
|
||||
$(BOOST_CPPFLAGS) \
|
||||
$(DEBUG_CXXFLAGS)
|
||||
|
||||
______lib_libfilterSample_a_SOURCES =
|
||||
______lib_libfilterSample_a_SOURCES = grey.cc
|
||||
|
19
src/filterSample/grey.cc
Normal file
19
src/filterSample/grey.cc
Normal 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
13
src/filterSample/grey.hh
Normal 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_ */
|
@ -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<VideoReader> { vr }, vw);
|
||||
// add filters
|
||||
// add filters here
|
||||
pipe.add_filter("grey");
|
||||
pipe.run();
|
||||
|
||||
return 0;
|
||||
|
@ -1,9 +1,21 @@
|
||||
#include "tbb/pipeline.h"
|
||||
|
||||
#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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -14,8 +14,7 @@
|
||||
class Pipeline
|
||||
{
|
||||
public:
|
||||
Pipeline(std::list<VideoReader> input, VideoWriter output)
|
||||
: input_(input), output_(output) {}
|
||||
Pipeline(std::list<VideoReader> input, VideoWriter output);
|
||||
bool add_filter(std::string filter);
|
||||
void run();
|
||||
private:
|
||||
|
Reference in New Issue
Block a user