diff options
| author | Comment <tim@gray.(none)> | 2013-08-20 02:47:59 +0100 |
|---|---|---|
| committer | Comment <tim@gray.(none)> | 2013-08-20 02:47:59 +0100 |
| commit | ad0e8b3e7f1d8889244f15134a00d1ac4803d9c3 (patch) | |
| tree | 31e49910fdd64db3f2c46869ab93b51c427e04fc | |
| parent | f485d31d2dd2e80f835b648115067a341f1b4fb3 (diff) | |
difference matte
| -rw-r--r-- | rotord/src/cvimage.cpp | 12 | ||||
| -rw-r--r-- | rotord/src/cvimage.h | 11 | ||||
| -rwxr-xr-x | rotord/src/rotor.cpp | 1 | ||||
| -rwxr-xr-x | rotord/src/rotor.h | 18 |
4 files changed, 34 insertions, 8 deletions
diff --git a/rotord/src/cvimage.cpp b/rotord/src/cvimage.cpp index 361999b..adf4267 100644 --- a/rotord/src/cvimage.cpp +++ b/rotord/src/cvimage.cpp @@ -126,6 +126,18 @@ namespace Rotor { } return *this; } + Image & Image::alpha_from_cv(cv::Mat &other){ + //if (other.w!=w||other.h!=h) { + // cerr<<"Rotor: cannot merge alpha with different size! (wanted "<<w<<"x"<<h<<", got "<<other.w<<"x"<<other.h<<")"<<endl; + //} + //else { + if (other.channels()==1) { + alpha=other; + } + else cv::cvtColor(other,alpha,CV_RGB2GRAY); + //} + return *this; + } Image & Image::operator=(const Image &other) { //can be optimised? was trying to use other.data.clone() setup(other.w,other.h); diff --git a/rotord/src/cvimage.h b/rotord/src/cvimage.h index 4921f78..dc421de 100644 --- a/rotord/src/cvimage.h +++ b/rotord/src/cvimage.h @@ -95,9 +95,10 @@ namespace Rotor { } bool clear(){ rgb.setTo(0); + return true; }; bool setup(int _w,int _h){ //set up with internal data - if (w!=_w|h!=h){ + if ((w!=_w)|(h!=_h)){ rgb.create(_h,_w,CV_8UC3); RGBdata=rgb.data; //can move to use the bare pointer eventually ownsRGBdata=false; //will not be necessary @@ -149,8 +150,11 @@ namespace Rotor { */ } bool setup_fromMat(cv::Mat& othermat){ - //here the mat belongs to another Image object - rgb=cv::Mat(othermat); + //here the mat belongs to another object + if (othermat.channels()==1) { + cv::cvtColor(othermat, rgb, CV_GRAY2RGB); + } + else rgb=othermat; RGBdata=rgb.data; //can move to use the bare pointer eventually ownsRGBdata=false; //will not be necessary w=rgb.rows; @@ -179,6 +183,7 @@ namespace Rotor { Image & alpha_blend(const Image &other); Image & alpha_blend_cv(const Image &other); Image & alpha_merge(const Image &other); + Image & alpha_from_cv(cv::Mat &other); Image & add_wrap(const Image &other); Image & divide_wrap(const Image &other); Image & operator*=(const float &amount); diff --git a/rotord/src/rotor.cpp b/rotord/src/rotor.cpp index 0284223..7ab9e54 100755 --- a/rotord/src/rotor.cpp +++ b/rotord/src/rotor.cpp @@ -22,6 +22,7 @@ Node_factory::Node_factory(){ add_type("monochrome",new Monochrome()); add_type("transform",new Transform()); add_type("alpha_merge",new Alpha_merge()); + add_type("difference_matte",new Difference_matte()); //nodes_audio_analysis.h add_type("audio_analysis",new Audio_analysis()); //nodes_maths.h diff --git a/rotord/src/rotor.h b/rotord/src/rotor.h index eb00104..a2e5876 100755 --- a/rotord/src/rotor.h +++ b/rotord/src/rotor.h @@ -20,6 +20,7 @@ #include "cvimage.h" #include "libavwrapper.h" +//using namespace cv; namespace Rotor { //forward declarations class Node; @@ -723,6 +724,7 @@ namespace Rotor { create_image_input("image input","Image input"); create_image_input("background input","Background input"); create_parameter("threshold","number","Difference threshold","Threshold",0.05f,0.0f,1.0f); + create_attribute("mode","Output {image|alpha}","output mode","alpha",{"image","alpha"}); title="Difference matte"; description="Create an alpha channel using a background reference picture"; }; @@ -734,15 +736,21 @@ namespace Rotor { Image *output(const Frame_spec &frame){ Image *in1=image_inputs[0]->get(frame); if (in1){ - //copy incoming image **writable Image *in2=image_inputs[1]->get(frame); if (in2) { cv::cvtColor(in1->rgb,greyfg,CV_RGB2GRAY); cv::cvtColor(in2->rgb,greybg,CV_RGB2GRAY); - //cv::absDiff(greybg,greyfg,greyDiff); - //adaptiveThreshold(greyDiff,parameters["threshold"].value,20,true,false); //int blockSize, int offset=0,bool invert=false, bool gauss=false); + cv::absdiff(greyfg,greybg,greyDiff); - image.alpha_merge(*in2); + //parameters["threshold"]->value + cv::threshold(greyDiff,mask,parameters["threshold"]->value,255,CV_THRESH_BINARY); //int block_size=3, double param1=5); //int blockSize, int offset=0,bool invert=false, bool gauss=false); + + //cv::adaptiveThreshold(greyDiff,mask,255,CV_ADAPTIVE_THRESH_GAUSSIAN_C,CV_THRESH_BINARY, 3,5); //int block_size=3, double param1=5); //int blockSize, int offset=0,bool invert=false, bool gauss=false); + image=(*in1); + if (attributes["mode"]->value=="image"){ + image.setup_fromMat(mask); + } + else image.alpha_from_cv(mask); return ℑ } //if there aren't 2 image inputs connected just return the first @@ -751,7 +759,7 @@ namespace Rotor { return nullptr; } private: - cv::Mat greyfg,greybg,greyDiff; + cv::Mat greyfg,greybg,greyDiff,mask; }; #define VIDEOFRAMES_still 1 #define VIDEOFRAMES_blend 2 |
