OpenCV无接缝石闪烁

2024-10-03 00:28:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个video,从中提取第一帧用作静态背景。对于视频的每一帧,我想用这个mask在静态背景上遮罩其中的一部分

不混合:

maskedFrame = cv2.bitwise_and(frame, frame, mask = mask)
maskedBackground = cv2.bitwise_and(staticBackground, staticBackground, mask = cv2.bitwise_not(mask))
output = maskedFrame + maskedBackground

Result

但是,我想使用泊松混合:

output = cv2.seamlessClone(frame, staticBackground, center, cv2.NORMAL_CLONE)

中心计算如下:

x,y,w,h = cv2.boundingRect(contours[0])
center = (int(x+w/2), int(y+h/2))

这将产生weird results and flickering, and what looks like a rectangular mask

我想可能是遮罩在移动的物体周围太紧了,所以我缩放了它的轮廓,但这并没有解决问题。我也尝试过用seamlessClone和maskedBackground代替staticBackground,但毫不奇怪,这也不起作用

对于这个问题,SeamlesClone是一个错误的选择还是我用错了


Tags: andoutputvideo静态maskcv2frameint