Ask Your Question
0

Displaying an image (in a specified location) over a video stream

asked 2016-11-15 12:53:06 -0600

Hi I am having trouble figuring out what function to use to display an image (test_image.jpg) over my webcam stream, sort of like a filter over the users face.

I have already figured out how to implement facial detection and I am able to display a circle over the face and as the face moves the image moves as well, but I want to know how to put an image over the face instead of the circle.

This is what I have to display a circle over the face:

Point center = Point(faces[i].x + faces[i].width0.5, faces[i].y + faces[i].height0.45);

circle(captureFrame, center, faces[i].width / 1.65, cvScalar(255, 0, 0, 0), 50, 8, 0);

imshow("outputFrame", captureFrame);

Thank you so much for the help!!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-11-15 22:15:42 -0600

So the Question is How to copy one Image to a part of another image?

int _tmain(int argc, _TCHAR* argv[])
{
    String  FileName1="\\opencv-master\\samples\\data\\lena.jpg", 
            FileName2="\\opencv-master\\samples\\data\\opencv-logo.png";
    Mat mSrc,mSrc_Crop,mSubImage;
    Rect rtFaceROI(200,170,160,230);

    mSrc= imread(FileName1,1);
    mSubImage= imread(FileName2,1);

    if(mSrc.empty()||mSubImage.empty())
    {
        cout<<"[Error]! Invalid Input Image\n";
        return 0;
    }

    imshow("mSrc",mSrc);
    imshow("Sub Image",mSubImage);

    resize(mSubImage,mSubImage,Size(rtFaceROI.width,rtFaceROI.height));

    mSrc_Crop= mSrc(rtFaceROI);//To Set an ROI 
    mSubImage.copyTo(mSrc_Crop);

    imshow("Sub Image",mSrc);   

    waitKey();
}

Input Image

image description

Output Image

image description

edit flag offensive delete link more

Comments

Hi Balaji, I actually want to place an image over a webcam stream (video).. This seems to be harder. I have a captureFrame that constantly updates but I am not sure how to apply the image on top of the video..

ryanluf gravatar imageryanluf ( 2016-11-16 08:47:08 -0600 )edit

Have you tried to read any tutorial ? See here http://docs.opencv.org/3.1.0/db/d28/t...

Balaji R gravatar imageBalaji R ( 2016-11-16 09:02:55 -0600 )edit

Yes, so I am using the Haar Cascades to display a circle over the video stream. However, I want to replace the circle with a photoshopped image and that's where I am having trouble. Thank you

ryanluf gravatar imageryanluf ( 2016-11-16 09:24:00 -0600 )edit

maybe this will be helpful.

sturkmen gravatar imagesturkmen ( 2016-11-17 01:51:16 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-11-15 12:50:05 -0600

Seen: 538 times

Last updated: Nov 15 '16