#### How to extract static scene or frames from video using image-processing in python?

I have a 1D list that has 2d elements which are frames of video, and I want to extract the consecutive static frames and consecutive frames that have moving objects in them.

I have tried to get the Pearson correlation equation between a frame and the frames which are next to it if the correlation is above a specified threshold then the frame is appended to another new list because it’s static.

``````def split_video(frames):
i = 0
static_sence = list()
static_sences = list()
while i < len(frames):
j = i+1
while j < len(frames):
corr_coff = correlation_equation(frames[i],frames[j]) #must be from -1 to 1
if  corr_coff >= 0.995:
static_sence.append(j+1) #append the number of frame to use it later
static_sence.append(frames[j])#append the frame next to its number
j+=1
else:
if len(static_sence) > 10: #more than five frames because the other five elements are
frame numbers not frame value

#append frame and its num i which was used in comparison operation with other
frames to static sence list
static_sence.insert(0,frames[i])
static_sence.insert(0,i)
#convert static sence to dict the key is frame no and the value is frame itself
static_sence = {static_sence[i]: static_sence[i + 1] for i in range(0,
len(static_sence), 2)}
#append every dict(static sub-sequence) to another list
static_sences.append(static_sence)
static_sence = []
i = j
break
else:
i = j
break
#this condition is to prevent infinty loop
if j == len(frames) -1:
i = len(frames) -1
break
``````

But I got an infinity loop or logical errors.
I hope you got my problem and understood my unclean code.

write a new code if that will solve the problem.

Source: Python Questions