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