Ask Your Question

Revision history [back]

with the code below i tried to achive desired result. i hope it helps.

references:

http://answers.opencv.org/question/1 @Alexander Shishkov

http://answers.opencv.org/question/21686 @berak

http://answers.opencv.org/question/37568 @Martin Peris

thanks all.

used image opencv-logo-150.png

#include "opencv2/opencv.hpp"

using namespace cv;

int main(int argc, char** argv)
{
    VideoCapture cap(0);

    if(!cap.open(0))
        return 0;

    int x, y;
    x = 100;
    y = 100;

    Mat mask;
    Mat c[4];

    Mat logo= imread("opencv-logo-150.png", -1);
    //Mat logo= imread("bmp.bmp", -1); // must have white background

    Size nsize(logo.cols / 2, logo.rows / 2);

    resize(logo,logo,nsize,0,0,INTER_NEAREST);
    //resize(logo,logo,nsize,0,0,INTER_LINEAR);
    //resize(logo,logo,nsize,0,0,INTER_CUBIC);
    //resize(logo,logo,nsize,0,0,INTER_AREA);
    //resize(logo,logo,nsize,0,0,INTER_LANCZOS4);


    if(logo.channels()==4)
    {
        split(logo,c);         // seperate channels
        Mat cs[3] = { c[0],c[1],c[2] };
        merge(cs,3,logo);  // glue together again
        mask = c[3];       // png's alpha channel used as mask
    }
    else
    {
    cvtColor( logo, mask, COLOR_BGR2GRAY );
    mask = mask < 255;
    }


    for(;;)
    {
        Mat frame;

        cap >> frame;
        if( frame.empty() ) break; // end of video stream

        logo.copyTo(frame(cv::Rect(x,y,logo.cols, logo.rows)),mask);

        imshow("VideoCapture", frame);
        if( waitKey(1) == 27 ) break; // stop capturing by pressing ESC
    }

    return 0;
}

with the code below i tried to achive desired result. result instead of using cv::seamlessClone. i hope it helps.

references:

http://answers.opencv.org/question/1 @Alexander Shishkov

http://answers.opencv.org/question/21686 @berak

http://answers.opencv.org/question/37568 @Martin Peris@martin-peris

thanks all.

used image opencv-logo-150.png

#include "opencv2/opencv.hpp"

using namespace cv;

int main(int argc, char** argv)
{
    VideoCapture cap(0);

    if(!cap.open(0))
        return 0;

    int x, y;
    x = 100;
    y = 100;

    Mat mask;
    Mat c[4];

    Mat logo= imread("opencv-logo-150.png", -1);
    //Mat logo= imread("bmp.bmp", -1); // must have white background

    Size nsize(logo.cols / 2, logo.rows / 2);

    resize(logo,logo,nsize,0,0,INTER_NEAREST);
    //resize(logo,logo,nsize,0,0,INTER_LINEAR);
    //resize(logo,logo,nsize,0,0,INTER_CUBIC);
    //resize(logo,logo,nsize,0,0,INTER_AREA);
    //resize(logo,logo,nsize,0,0,INTER_LANCZOS4);


    if(logo.channels()==4)
    {
        split(logo,c);         // seperate channels
        Mat cs[3] = { c[0],c[1],c[2] };
        merge(cs,3,logo);  // glue together again
        mask = c[3];       // png's alpha channel used as mask
    }
    else
    {
    cvtColor( logo, mask, COLOR_BGR2GRAY );
    mask = mask < 255;
    }


    for(;;)
    {
        Mat frame;

        cap >> frame;
        if( frame.empty() ) break; // end of video stream

        logo.copyTo(frame(cv::Rect(x,y,logo.cols, logo.rows)),mask);

        imshow("VideoCapture", frame);
        if( waitKey(1) == 27 ) break; // stop capturing by pressing ESC
    }

    return 0;
}

with the code below i tried to achive desired result instead of using cv::seamlessClone. i hope it helps.

references:

http://answers.opencv.org/question/1 @Alexander Shishkov

http://answers.opencv.org/question/21686 @berak

http://answers.opencv.org/question/37568 @martin-peris@Martin Peris

thanks all.

used image opencv-logo-150.png

#include "opencv2/opencv.hpp"

using namespace cv;

int main(int argc, char** argv)
{
    VideoCapture cap(0);

    if(!cap.open(0))
        return 0;

    int x, y;
    x = 100;
    y = 100;

    Mat mask;
    Mat c[4];

    Mat logo= imread("opencv-logo-150.png", -1);
    //Mat logo= imread("bmp.bmp", -1); // must have white background

    Size nsize(logo.cols / 2, logo.rows / 2);

    resize(logo,logo,nsize,0,0,INTER_NEAREST);
    //resize(logo,logo,nsize,0,0,INTER_LINEAR);
    //resize(logo,logo,nsize,0,0,INTER_CUBIC);
    //resize(logo,logo,nsize,0,0,INTER_AREA);
    //resize(logo,logo,nsize,0,0,INTER_LANCZOS4);


    if(logo.channels()==4)
    {
        split(logo,c);         // seperate channels
        Mat cs[3] = { c[0],c[1],c[2] };
        merge(cs,3,logo);  // glue together again
        mask = c[3];       // png's alpha channel used as mask
    }
    else
    {
    cvtColor( logo, mask, COLOR_BGR2GRAY );
    mask = mask < 255;
    }


    for(;;)
    {
        Mat frame;

        cap >> frame;
        if( frame.empty() ) break; // end of video stream

        logo.copyTo(frame(cv::Rect(x,y,logo.cols, logo.rows)),mask);

        imshow("VideoCapture", frame);
        if( waitKey(1) == 27 ) break; // stop capturing by pressing ESC
    }

    return 0;
}

with the code below i tried to achive desired result instead of using cv::seamlessClone. i hope it helps.

references:

http://answers.opencv.org/question/1 @Alexander Shishkov

http://answers.opencv.org/question/21686 @berak

http://answers.opencv.org/question/37568 @Martin Martin Peris

thanks all.

used image opencv-logo-150.png

#include "opencv2/opencv.hpp"

using namespace cv;

int main(int argc, char** argv)
{
    VideoCapture cap(0);

    if(!cap.open(0))
        return 0;

    int x, y;
    x = 100;
    y = 100;

    Mat mask;
    Mat c[4];

    Mat logo= imread("opencv-logo-150.png", -1);
    //Mat logo= imread("bmp.bmp", -1); // must have white background

    Size nsize(logo.cols / 2, logo.rows / 2);

    resize(logo,logo,nsize,0,0,INTER_NEAREST);
    //resize(logo,logo,nsize,0,0,INTER_LINEAR);
    //resize(logo,logo,nsize,0,0,INTER_CUBIC);
    //resize(logo,logo,nsize,0,0,INTER_AREA);
    //resize(logo,logo,nsize,0,0,INTER_LANCZOS4);


    if(logo.channels()==4)
    {
        split(logo,c);         // seperate channels
        Mat cs[3] = { c[0],c[1],c[2] };
        merge(cs,3,logo);  // glue together again
        mask = c[3];       // png's alpha channel used as mask
    }
    else
    {
    cvtColor( logo, mask, COLOR_BGR2GRAY );
    mask = mask < 255;
    }


    for(;;)
    {
        Mat frame;

        cap >> frame;
        if( frame.empty() ) break; // end of video stream

        logo.copyTo(frame(cv::Rect(x,y,logo.cols, logo.rows)),mask);

        imshow("VideoCapture", frame);
        if( waitKey(1) == 27 ) break; // stop capturing by pressing ESC
    }

    return 0;
}