[英]Overlay image on a video using opencv
I used this function to put an overlay image using OpenCV. 我使用此功能使用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 隐藏像
OverlayImage(temp, tempad, cvPoint(10, 10), cvScalar(1,1,1,1), cvScalar(0,0,0,0));
for displaying 用于显示
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. 但是第一张图像的区域有些失真,我希望使该图像在400帧视频后消失。 How can I make that area clear ?
如何使该区域清晰?
Please help! 请帮忙!
好了,您可以复制不带叠加层的图像 ,然后,当您不想显示叠加的图像时,可以显示副本 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.