(ret,data_map) = cv2.threshold(cv2.cvtColor(next_img_warp, cv2.COLOR_BGR2GRAY), 0, 255, cv2.THRESH_BINARY)
(ret_base,data_map_base) = cv2.threshold(cv2.cvtColor(base_img_warp, cv2.COLOR_BGR2GRAY), 0, 255, cv2.THRESH_BINARY)
firstly I converted two images to grayscale.Then I use cv2.bitwise_and()
to get the mask of the overlapping part.
mask =cv2.bitwise_and(data_map,data_map_base)
inv_mask = cv2.bitwise_not(mask)
then I used the mask to get three parts:
base_cross = cv2.add(base, base_img_warp, mask=mask, dtype=cv2.CV_8U)
next_cross = cv2.add(base, next_img_warp, mask=mask, dtype=cv2.CV_8U)
base_not_cross = cv2.add(base, base_img_warp, mask=inv_mask, dtype=cv2.CV_8U)
next_not_cross = cv2.add(base, next_img_warp, mask=inv_mask, dtype=cv2.CV_8U)
base
is a black base image.
then I do linear blending using base_cross
and next_cross
and get the blended overlapping part cross_blend =self.blendImage(base_cross,next_cross)
finally I put the three parts back together using cv2.add
and the mask:
base_not_cross = cv2.add(enlarged_base_img, base_img_warp, mask=inv_mask, dtype=cv2.CV_8U)
next_not_cross = cv2.add(enlarged_base_img, next_img_warp, mask=inv_mask, dtype=cv2.CV_8U)
final_img = cv2.add(base_not_cross, next_not_cross, dtype=cv2.CV_8U)
final_img = cv2.add(final_img, cross_blend, dtype=cv2.CV_8U)
But my question is, why I got these black seams in result images, even I put original base_cross
or next_cross
back instead of the blended cross_blend
? What could I do to eliminate these black seams?
here's my result image: https://i.stack.imgur.com/jtiQO.jpg