diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-08-30 12:46:09 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-08-30 12:46:09 +0100 |
| commit | 949a501117d17ec29e29e63dfbab33f3d933c75e (patch) | |
| tree | 9f0979748f79384c584de241b7ebda0729b81c1a | |
| parent | 9570eb7a5eb70128f7b986a281dd163263858ba1 (diff) | |
transform base class
| -rw-r--r-- | rotord/src/nodes_transform.h | 90 |
1 files changed, 3 insertions, 87 deletions
diff --git a/rotord/src/nodes_transform.h b/rotord/src/nodes_transform.h index b7314bf..69a0af6 100644 --- a/rotord/src/nodes_transform.h +++ b/rotord/src/nodes_transform.h @@ -30,9 +30,7 @@ namespace Rotor { }; ~Transformer(){ }; - Transformer* clone(map<string,string> &_settings) { return new Transformer(_settings);}; - Image *output(const Frame_spec &frame){ - Image *in=image_inputs[0]->get(frame); + Image *transform(Image *in){ if (in){ int filtmode; switch(attributes["filter"]->intVal){ @@ -106,21 +104,10 @@ namespace Rotor { } private: }; - class Transform: public Image_node { - //what is the best coordinate system to use? - //origin: corner or centre - //units: pixel or fractional - //aspect: scaled or homogenous + class Transform: public Transformer { public: Transform(){ create_image_input("image input","Image input"); - create_parameter("transformX","number","X transformation","Transform X",0.0f); - create_parameter("transformY","number","Y transformation","Transform X",0.0f); - create_parameter("originX","number","X transformation origin","Origin X",0.5f); - create_parameter("originY","number","Y transformation origin","Origin Y",0.5f); - create_parameter("rotation","number","Rotation about origin","Rotation",0.0f); - create_parameter("scale","number","Scale about origin","Scale",1.0f); - create_attribute("filter","Filtering mode","Filter mode","linear",{"nearest","linear","area","cubic","lanczos"}); title="Transform"; description="Apply 2D transformation"; }; @@ -131,81 +118,10 @@ namespace Rotor { }; Transform* clone(map<string,string> &_settings) { return new Transform(_settings);}; Image *output(const Frame_spec &frame){ - Image *in=image_inputs[0]->get(frame); - if (in){ - int filtmode; - switch(attributes["filter"]->intVal){ - case TRANSFORM_nearest: - filtmode=cv::INTER_NEAREST; - break; - case TRANSFORM_linear: - filtmode=cv::INTER_LINEAR; - break; - case TRANSFORM_area: - filtmode=cv::INTER_AREA; - break; - case TRANSFORM_cubic: - filtmode=cv::INTER_CUBIC; - break; - case TRANSFORM_lanczos: - filtmode=cv::INTER_LANCZOS4; - break; - } - - float tX=parameters["transformX"]->value; - float tY=parameters["transformY"]->value; - float oX=parameters["originX"]->value; - float oY=parameters["originY"]->value; - float r=parameters["rotation"]->value; - float s=parameters["scale"]->value; - - //do opencv transform - cv::Point2f srcTri[3], dstTri[3]; - cv::Mat rot_mat(2,3,CV_32FC1); - cv::Mat trans_mat(2,3,CV_32FC1); - - Image inter; - inter.setup(in->w,in->h); - // Compute matrix by creating triangle and transforming - //is there a better way - combine the 2? Just a bit of geometry - srcTri[0].x=0; - srcTri[0].y=0; - srcTri[1].x=in->w-1; - srcTri[1].y=0; - srcTri[2].x=0; - srcTri[2].y=in->h-1; - for (int i=0;i<3;i++){ - dstTri[i].x=srcTri[i].x+(tX*in->w); - dstTri[i].y=srcTri[i].y+(tY*in->h); - } - trans_mat=getAffineTransform( srcTri, dstTri ); - warpAffine( in->rgb, inter.rgb, trans_mat, inter.rgb.size(), filtmode, cv::BORDER_WRAP); - - - // Compute rotation matrix - // - cv::Point centre = cv::Point( oX*in->w, oY*in->h ); - - rot_mat = getRotationMatrix2D( centre, r, s ); - // Do the transformation - // - - warpAffine( inter.rgb, image.rgb, rot_mat, image.rgb.size(), filtmode, cv::BORDER_WRAP); - //BORDER_WRAP - - //INTER_NEAREST - a nearest-neighbor interpolation - //INTER_LINEAR - a bilinear interpolation (used by default) - //INTER_AREA - resampling using pixel area relation. It may be a preferred method for image decimation, as it gives moire’-free results. But when the image is zoomed, it is similar to the INTER_NEAREST method. - //INTER_CUBIC - a bicubic interpolation over 4x4 pixel neighborhood - //INTER_LANCZOS4 - a Lanczos interpolation over 8x8 pixel neighborhood - - return ℑ - } - return nullptr; + return transform(image_inputs[0]->get(frame)); } private: }; - //Transform and Still could inherit from a transformer node class Still_image: public Image_node { public: Still_image(){ |
