Opencv學習——圖像融合

Opencv相關函數:

C++: void seamlessClone(InputArray src, InputArray dst, InputArray mask, Point p, OutputArray blend, int flags)

圖像融合基本原理:泊松克隆,與圖像的梯度和散度相關,具體的原理可查看

http://blog.csdn.net/hjimce/article/details/45716603


圖像融合效果:

這裏寫圖片描述
其中,原圖如下:
這裏寫圖片描述


相關代碼:

int main()
{
    // Read images : src image will be cloned into dst
    Mat src = imread("bird.jpg");
    Mat dst = imread("sunset.jpg");
    resize(dst, dst, Size(dst.cols/2, dst.rows/2));

    // Create an all white mask
    Mat src_mask = Mat::zeros(src.rows, src.cols, src.depth());

    // Define the mask as a closed polygon
    Point poly[1][4];
    poly[0][0] = Point(263, 127);
    poly[0][1] = Point(257, 265);
    poly[0][2] = Point(720, 338);
    poly[0][3] = Point(721, 138);

    const Point* polygons[1] = { poly[0] };
    int num_points[] = { 4 };

    // Create mask by filling the polygon
    fillPoly(src_mask, polygons, num_points, 1, Scalar(255, 255, 255));

    // The location of the center of the src in the dst
    Point center(700, 150);

    // Seamlessly clone src into dst and put the results in output
    Mat output;
    seamlessClone(src, dst, src_mask, center, output, NORMAL_CLONE);

    imshow("result", output);
    waitKey(0);

    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章