У меня есть видео с непрозрачным логотипом, моя цель - определить область изображения, которая остается неподвижной, и извлечь ее.
это мой код:
import cv2
import numpy as np
import imutils
c = cv2.VideoCapture('sky.mp4')
_,f = c.read()
avg2 = np.float32(f)
while(1):
_,f = c.read()
cv2.accumulateWeighted(f,avg2,0.005)
#cv2.accumulateWeighted(f,avg2,0.01)
res2 = cv2.convertScaleAbs(avg2)
# load the query image, compute the ratio of the old height
# to the new height, clone it, and resize it
ratio = res2.shape[0] / 300.0
orig = res2.copy()
res2 = imutils.resize(res2, height = 600)
# convert the image to grayscale, blur it, and find edges
# in the image
gray = cv2.cvtColor(res2, cv2.COLOR_BGR2GRAY)
gray = cv2.bilateralFilter(gray, 11, 17, 17)
edged = cv2.Canny(gray, 30, 200)
cv2.imshow('img',f)
cv2.imshow('avg2',edged)
k = cv2.waitKey(20)
if k == 27:
break
cv2.destroyAllWindows()
c.release()
Функция cv2.accumulateWeighted после истечения времени позволяет четко идентифицировать части, которые в основном остаются на кадрах.
оригинальная рамка:
![enter image description here](https://i.stack.imgur.com/ra4Vh.jpg)
усредненная рамочная часть:
![enter image description here](https://i.stack.imgur.com/MM3zw.jpg)
Как создать маску для всей усредненной кромочной части, обрезать ее и сохранить в отдельном изображении?