double Width = (end_x - start_x);//重叠区域的宽度 //图像加权融合,通过改变alpha修改DstImg与WarpImg像素权重,达到融合效果 double alpha = 1.0; for (int i = 0; i < DstImg.rows; i++) { for (int j = start_x; j < end_x; j++) { for (int c = 0; c < 3; c++) { //如果图像WarpImg像素为0,则完全拷贝DstImg if (WarpImg.at<Vec3b>(i, j)[c] == 0) { alpha = 1.0; } else { double l = Width - (j - start_x); //重叠区域中某一像素点到拼接缝的距离 alpha = l / Width; } DstImg.at<Vec3b>(i, j)[c] = DstImg.at<Vec3b>(i, j)[c] * alpha + WarpImg.at<Vec3b>(i, j)[c] * (1.0 - alpha); } } }将这段c++代码转换成python代码
时间: 2024-01-15 21:03:20 浏览: 63
获取两张图片重叠部分,并融合
3星 · 编辑精心推荐
width = end_x - start_x # 重叠区域的宽度
alpha = 1.0
for i in range(DstImg.shape[0]):
for j in range(start_x, end_x):
for c in range(3):
if WarpImg[i, j, c] == 0:
alpha = 1.0
else:
l = width - (j - start_x)
alpha = l / width
DstImg[i, j, c] = DstImg[i, j, c] * alpha + WarpImg[i, j, c] * (1.0 - alpha)
阅读全文