我有一个video,从中提取第一帧用作静态背景。对于视频的每一帧,我想用这个mask在静态背景上遮罩其中的一部分
不混合:
maskedFrame = cv2.bitwise_and(frame, frame, mask = mask)
maskedBackground = cv2.bitwise_and(staticBackground, staticBackground, mask = cv2.bitwise_not(mask))
output = maskedFrame + maskedBackground
但是,我想使用泊松混合:
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是一个错误的选择还是我用错了
我发现SeamlesClone会在每一帧后反转遮罩。 它可以通过拥有掩码的deepcopy来修复,或者在每次迭代后反转掩码,使其返回到原始掩码
相关问题 更多 >
编程相关推荐