Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

stitch 2 images

I want to place one image on another(and optionally then blend them). I have just shift, for example I have shift point of 2nd image relative to epper left corner of 1st image (coordinates of point can be negative). Is there any prebuild finction to do this? something like align(Mat im1,Mat im2,Point pt,Mat out);

stitch 2 images

I want to place one image on another(and optionally then blend them). I have just shift, for example I have shift point of 2nd image relative to epper upper left corner of 1st image (coordinates of point can be negative). Is there any prebuild finction to do this? something like align(Mat im1,Mat im2,Point pt,Mat out);

stitch 2 images

I want to place one image on another(and optionally then blend them). I have just shift, for example I have shift point of 2nd image relative to upper left corner of 1st image (coordinates of point can be negative). Is there any prebuild finction to do this? something like align(Mat im1,Mat im2,Point pt,Mat out);

here is the code:

void align(Mat_<uchar> src, Mat_<uchar> tmp,Mat_<uchar> out,int cx,int cy)
{
    int w_s= src.cols;
    int h_s= src.rows;
    int w_t= tmp.cols;
    int h_t= tmp.rows;
    if(cx>=0&&cy>=0)
    {
        out.create(max(cy+h_t,h_s),max(cx+w_t,w_s));
        src.copyTo(out(Rect(0,0,src.cols,src.rows)));
        tmp.copyTo(out(Rect(cx,cy,tmp.cols,tmp.rows)));
    }
    else if(cx>=0&&cy<0)
    {
        out.create(max(h_t-abs(cy),abs(cy)+h_s),max(cx+w_t,w_s));
        src.copyTo(out(Rect(0,abs(cy),src.cols,src.rows)));
        tmp.copyTo(out(Rect(cx,0,tmp.cols,tmp.rows)));
    }
    else if(cx<0&&cy>=0)
    {
        out.create(max(cy+h_t,h_s),max(w_t-abs(cx),abs(cx)+w_s));
        src.copyTo(out(Rect(abs(cx),0,src.cols,src.rows)));
        tmp.copyTo(out(Rect(0,cy,tmp.cols,tmp.rows)));
    }
    else if(cx<0&&cy<0)
    {
        out.create(max(h_t-abs(cy),abs(cy)+h_s),max(w_t-abs(cx),abs(cx)+w_s));
        src.copyTo(out(Rect(abs(cx),abs(cy),src.cols,src.rows)));
        tmp.copyTo(out(Rect(0,0,tmp.cols,tmp.rows)));
    }

    imwrite("pyr/align.png",out);
    return;
}

stitch 2 images

I want to place one image on another(and optionally then blend them). I have just shift, for example I have shift point of 2nd image relative to upper left corner of 1st image (coordinates of point can be negative). Is there any prebuild finction to do this? something like align(Mat im1,Mat im2,Point pt,Mat out);

here is the code:

void align(Mat_<uchar> src, Mat_<uchar> tmp,Mat_<uchar> out,int cx,int cy)
{
    int w_s= src.cols;
    int h_s= src.rows;
    int w_t= tmp.cols;
    int h_t= tmp.rows;
    if(cx>=0&&cy>=0)
    {
        out.create(max(cy+h_t,h_s),max(cx+w_t,w_s));
        src.copyTo(out(Rect(0,0,src.cols,src.rows)));
        tmp.copyTo(out(Rect(cx,cy,tmp.cols,tmp.rows)));
    }
    else if(cx>=0&&cy<0)
    {
        out.create(max(h_t-abs(cy),abs(cy)+h_s),max(cx+w_t,w_s));
        src.copyTo(out(Rect(0,abs(cy),src.cols,src.rows)));
        tmp.copyTo(out(Rect(cx,0,tmp.cols,tmp.rows)));
    }
    else if(cx<0&&cy>=0)
    {
        out.create(max(cy+h_t,h_s),max(w_t-abs(cx),abs(cx)+w_s));
        src.copyTo(out(Rect(abs(cx),0,src.cols,src.rows)));
        tmp.copyTo(out(Rect(0,cy,tmp.cols,tmp.rows)));
    }
    else if(cx<0&&cy<0)
    {
        out.create(max(h_t-abs(cy),abs(cy)+h_s),max(w_t-abs(cx),abs(cx)+w_s));
        src.copyTo(out(Rect(abs(cx),abs(cy),src.cols,src.rows)));
        tmp.copyTo(out(Rect(0,0,tmp.cols,tmp.rows)));
    }

    imwrite("pyr/align.png",out);
    return;
}

stitch 2 images

I want to place one image on another(and optionally then blend them). I have just shift, for example I have shift point of 2nd image relative to upper left corner of 1st image (coordinates of point can be negative). Is there any prebuild finction to do this? something like align(Mat im1,Mat im2,Point pt,Mat out);

here is the code:

void align(Mat_<uchar> Mat align(Mat src, Mat_<uchar> tmp,Mat_<uchar> out,int Mat tmp,int cx,int cy)
{
    int w_s= src.cols;
 int h_s= src.rows;
 int w_t= tmp.cols;
 int h_t= tmp.rows;
 Mat out;
if(cx>=0&&cy>=0)
 {
        out.create(max(cy+h_t,h_s),max(cx+w_t,w_s));
    out.create(max(cy+h_t,h_s),max(cx+w_t,w_s),src.type());
    src.copyTo(out(Rect(0,0,src.cols,src.rows)));
     tmp.copyTo(out(Rect(cx,cy,tmp.cols,tmp.rows)));
 }
 else if(cx>=0&&cy<0)
 {
        out.create(max(h_t-abs(cy),abs(cy)+h_s),max(cx+w_t,w_s));
    out.create(max(h_t-abs(cy),abs(cy)+h_s),max(cx+w_t,w_s),src.type());
    src.copyTo(out(Rect(0,abs(cy),src.cols,src.rows)));
     tmp.copyTo(out(Rect(cx,0,tmp.cols,tmp.rows)));
 }
 else if(cx<0&&cy>=0)
 {
        out.create(max(cy+h_t,h_s),max(w_t-abs(cx),abs(cx)+w_s));
    out.create(max(cy+h_t,h_s),max(w_t-abs(cx),abs(cx)+w_s),src.type());
    src.copyTo(out(Rect(abs(cx),0,src.cols,src.rows)));
     tmp.copyTo(out(Rect(0,cy,tmp.cols,tmp.rows)));
 }
 else if(cx<0&&cy<0)
 {
        out.create(max(h_t-abs(cy),abs(cy)+h_s),max(w_t-abs(cx),abs(cx)+w_s));
    out.create(max(h_t-abs(cy),abs(cy)+h_s),max(w_t-abs(cx),abs(cx)+w_s),src.type());
    src.copyTo(out(Rect(abs(cx),abs(cy),src.cols,src.rows)));
     tmp.copyTo(out(Rect(0,0,tmp.cols,tmp.rows)));
 }
    return;
return out;
}