seamlessClone flickering
I have a video, from which I extract the first frame to use as a static background. For each frame of the video, I would like to mask a part of it on top of the static background, using this mask. Without blending:
maskedFrame = cv2.bitwise_and(frame, frame, mask = mask)
maskedBackground = cv2.bitwise_and(staticBackground, staticBackground, mask = cv2.bitwise_not(mask))
output = maskedFrame + maskedBackground
However, I would like to use Poisson blending:
output = cv2.seamlessClone(frame, staticBackground, center, cv2.NORMAL_CLONE)
With the center computed like so:
x,y,w,h = cv2.boundingRect(contours[0])
center = (int(x+w/2), int(y+h/2))
This produces weird results and flickering, and what looks like a rectangular mask. I thought maybe the mask was too tight around the moving object, so I scaled its contour but that didn't fix the problem. I also tried seamlessClone with maskedBackground instead of staticBackground but, unsurprisingly, that didn't work either. Is seamlessClone a wrong choice for this problem or am I using it incorrectly?
This could be wrong:
Actually, could be similar:
Hope this help.
Thank you for the reply.
Unfortunately, it has not fixed my problem. I think the two codes produce the same result. I don't think it's a problem with the center coordinates, as the mask looks aligned with the background.
Edit: I have solved the problem, but can't post the answer yet as I'm a new user.