I'm working on stitching multiple images using OpenCV. It's starting to work but I have a problem with one thing. After cv2.warpPerspective
image has a "soft" borders, which means that calculated mask is one pixel too big.
My code:
# 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)
I had to use cv2.bitwise_or
because adding both images using cv2.add
makes it too bright which made an almost black line at the connection.
Do you have any idea how to fix this? Maybe there's a way to modify mask to make it 1 pixel smaller?