Opencv学习——图像融合
程序员文章站
2024-03-21 23:27:46
...
Opencv相关函数:
C++: void seamlessClone(InputArray src, InputArray dst, InputArray mask, Point p, OutputArray blend, int flags)
图像融合基本原理:泊松克隆,与图像的梯度和散度相关,具体的原理可查看
图像融合效果:
其中,原图如下:
相关代码:
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;
}