0
我正在使用OpenCV拼接多个图像。它开始工作,但我遇到了一件事情。 cv2.warpPerspective
图像之后有一个“软”边框,这意味着计算的蒙版是一个像素太大。图像拼接神器[OpenCV Python]
我的代码:
# apply a perspective warp to stitch the images
# together
result = cv2.warpPerspective(imageA, H,
(imageA.shape[1] + imageB.shape[1], imageA.shape[0]))
# Now create a mask of logo and create its inverse mask also
img2gray = cv2.cvtColor(result,cv2.COLOR_BGR2GRAY)
ret, mask = cv2.threshold(img2gray, 0, 255, cv2.THRESH_BINARY)
mask_inv = cv2.bitwise_not(mask)
resizedB = np.zeros((result.shape[0],result.shape[1],3), np.uint8)
resizedB[0:imageB.shape[0], 0:imageB.shape[1]] = imageB
difference = cv2.bitwise_or(resizedB,result, mask=mask_inv)
result = cv2.add(result,difference)
cv2.imwrite('result .jpg', result)
我不得不使用cv2.bitwise_or
因为使用cv2.add
将两个图像使得它太亮,这使得在连接几乎黑线。 你有什么想法如何解决这个问题?也许有一种方法可以修改遮罩,使其缩小1个像素?
你可以使用一个梯度面具在转变,换句话说,既融合对接面 – Pedro
有没有办法用颜色阈值来获得梯度面具?我不认为有。你知道任何其他方式来获得这样的面具使用给定的图片吗? – Ekci
你可以计算距离图像边界的距离,类似于http://stackoverflow.com/questions/37911062/how-to-obtain-the-right-alpha-value-to-perfectly-blend-two-images/37918596# 37918596并将其用作混合蒙版 – Micka