blending two images by Opencv

后端 未结 3 1549
执念已碎
执念已碎 2021-01-21 17:18

I want to align two images of different sizes using Opencv, Indeed the function cvAddWeighted enables us to combine or blend two images of identical sizes which is not my case !

3条回答
  •  攒了一身酷
    2021-01-21 17:41

    You write a Rect_from_Mat function which returns Rect(0, 0, img.rows, img.cols).

    Then:

    Rect roi = Rect_from_Mat(img1) & Rect_from_Mat(img2);
    
    Mat img1_roi = img1(roi), img2_roi = img2(roi);
    if(results_in_img1)
    {
      addWeighted(img1_roi, alpha, img2_roi, beta, gamma, img1_roi);
      return img1;
    }
    

    Note that the 'addWeighted' line will (indirectly) overwrite img1's image data.

提交回复
热议问题