将图像放在图像上
c++
image-processing
opencv
5
0

我想将图像放置在捕获的视频帧上我确定的坐标处。

我之前问过这个问题,有人告诉我要使用cvCopycvSetImageROI但是我不想在这些坐标上裁剪,所以我想添加另一张图像。也许这是正确的方法,但我不理解(如果正确,请解释一下)。

参考资料:
Stack Overflow
收藏
评论
共 2 个回答
高赞 时间 活跃

我前一段时间使用SetRoi做到了,就像这样。我有两个图像,一个是称为thumb_frame的缩略图,这是我将包含在大图像中的小图片show_frame

//I set the ROI to the same size as the thumb_frame
cvSetImageROI(show_frame.image, cvRect(thumbnail_x_pos,
                    thumbnail_y_pos, thumb_frame->width, thumb_frame->height));

//I add the image to the designated ROI
cvAddWeighted(thumb_frame, alpha, show_frame, beta, 0, show_frame);

就是这样

收藏
评论
void cvOverlayImage(IplImage* src, IplImage* overlay, CvPoint location, CvScalar S, CvScalar D)
{
 int x,y,i;

  for(x=0;x < overlay->width -10;x++)     
//replace '-10' by whatever x position you want your overlay image to begin. 
//say '-varX'
    {
        if(x+location.x>=src->width) continue;
        for(y=0;y < overlay->height -10;y++)  
//replace '-10' by whatever y position you want your overlay image to begin.
//say '-varY'
        {
            if(y+location.y>=src->height) continue;
            CvScalar source = cvGet2D(src, y+location.y, x+location.x);
            CvScalar over = cvGet2D(overlay, y, x);
            CvScalar merged;
            for(i=0;i<4;i++)
            merged.val[i] = (S.val[i]*source.val[i]+D.val[i]*over.val[i]);
            cvSet2D(src, y+location.y, x+location.x, merged);
        }
    }
}

使用它

cvOverlayImage(largerimage, overlayimage, cvPoint(10, 10), cvScalar(0.5,0.5,0.5,0.5), cvScalar(0.5,0.5,0.5,0.5)); 
//The cvPoint(10,10) can be the cvPoint(varX,varY) depending on how you write the function 
//and how you want to use it. 
//You cannot choose values less than 'varX' and 'varY' in this case
//else you would see a runtime error.
收藏
评论
新手导航
  • 社区规范
  • 提出问题
  • 进行投票
  • 个人资料
  • 优化问题
  • 回答问题

关于我们

常见问题

内容许可

联系我们

@2020 AskGo
京ICP备20001863号