Ask Your Question

Revision history [back]

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

Result

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?

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

Result

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?