Place an image on an image

前端 未结 4 1743
隐瞒了意图╮
隐瞒了意图╮ 2020-12-29 14:34

I want to place an image on a captured video frame at the coordinates which I determined.

I asked that before and I have been told to use cvCopy and

4条回答
  •  情话喂你
    2020-12-29 14:52

    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);
            }
        }
    }
    

    To use it

    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.
    

提交回复
热议问题