简体   繁体   中英

Overlay image on a video using opencv

I used this function to put an overlay image using OpenCV.

void OverlayImage(IplImage* src, IplImage* overlay, CvPoint location, CvScalar S, CvScalar D) {
for (int i = location.y; i < (location.y + overlay->height); i++) {
    for (int j = location.x; j < (location.x + overlay->width); j++) {
        CvScalar source = cvGet2D(src, i, j);
        CvScalar over   = cvGet2D(overlay, i-location.y, j-location.x);
        CvScalar merged;

        for(int i = 0; i < 4; i++)
            merged.val[i] = (S.val[i] * source.val[i] + D.val[i] * over.val[i]);

        cvSet2D(src, i + location.y, j + location.x, merged);
    }
}
}

and then used the function like this -

OverlayImage(temp, tempad, cvPoint(10, 10), cvScalar(0,0,0,0), cvScalar(1,1,1,1)); 

for hiding the overlay image like 图片1

OverlayImage(temp, tempad, cvPoint(10, 10), cvScalar(1,1,1,1), cvScalar(0,0,0,0)); 

for displaying image2

The way I used those functions is :

if (frame_number < 400)
    OverlayImage(temp, tempad, cvPoint(10, 10), cvScalar(1,1,1,1), cvScalar(0,0,0,0));
else 
    OverlayImage(temp, tempad, cvPoint(10, 10), cvScalar(0,0,0,0), cvScalar(1,1,1,1));

But the first image has some distorted area, I wish to make that image disappear after 400 frames of the video. How can I make that area clear ?

Please help!

好了,您可以复制不带叠加层的图像 ,然后,当您不想显示叠加的图像时,可以显示副本

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM