diff options
Diffstat (limited to 'rotord/rotor.h')
| -rwxr-xr-x | rotord/rotor.h | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/rotord/rotor.h b/rotord/rotor.h index 953a69b..3f51d79 100755 --- a/rotord/rotor.h +++ b/rotord/rotor.h @@ -1160,6 +1160,75 @@ namespace Rotor { private: Image image; }; + 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 + public: + Transform(){}; + Transform(map<string,string> &settings) { + base_settings(settings); + tX=find_setting(settings,"transformX",0.0f); + tY=find_setting(settings,"transformY",0.0f); + oX=find_setting(settings,"originX",0.5f); + oY=find_setting(settings,"originX",0.5f); + r=find_setting(settings,"rotation",0.0f); + s=find_setting(settings,"scale",1.0f); + }; + ~Transform(){ + }; + Transform* clone(map<string,string> &_settings) { return new Transform(_settings);}; + Image *output(const Frame_spec &frame){ + if (image_inputs.size()) { + if (image_inputs[0]->connection){ + Image *other=(((Image_node*)image_inputs[0]->connection)->get_output(frame)); + if (other) { + image.setup(other->w,other->h); + //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(other->w,other->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=other->w-1; + srcTri[1].y=0; + srcTri[2].x=0; + srcTri[2].y=other->h-1; + for (int i=0;i<3;i++){ + dstTri[i].x=srcTri[i].x+(tX*other->w); + dstTri[i].y=srcTri[i].y+(tY*other->h); + } + trans_mat=getAffineTransform( srcTri, dstTri ); + warpAffine( other->rgb, inter.rgb, trans_mat, inter.rgb.size() ); + */ + + // Compute rotation matrix + // + cv::Point centre = cv::Point( oX*other->w, oY*other->h ); + + rot_mat = getRotationMatrix2D( centre, r, s ); + // Do the transformation + // + warpAffine( other->rgb, image.rgb, rot_mat, image->rgb.size() ); + + return ℑ + } + } + } + return nullptr; + } + private: + Image image; + float tX,tY,oX,oY,r,s; + //todo - quality settings + }; //------------------------------------------------------------------- class Node_factory{ public: |
