I have just started doing my project with python.
I want to extract the background in a video by considering the values of each pixels which has higher occurrence in the entire video. for this, I want to add the pixel values for each frame to the previous ones.
To make it more simplified, for example, I have a video with total frame of 400. the frame size is 100X300. For each loop, I want to append (concatenate) by the values of a current frame. So, after each loop (for reading the frame in video), the size of the array should be increase in the third dimentions by 1 and in total after reading all frames, I should have an array with size (100X300X400)-> an array with 100 rows, 300 columns and 400 depth!
Then, I will calculate the histogram for each pixel.
Your help is really appreciated.
I am using OpenCV 3.1 and Python 2.7.12 using Pycharm.
import numpy as np
c = cv2.VideoCapture('NonStop_stab.mp4')
width = c.get(cv2.CAP_PROP_FRAME_WIDTH)
height = c.get(cv2.CAP_PROP_FRAME_HEIGHT)
size = (int(width), int(height))
_, f = c.read()
#Here is the part I am asking
result_array = np.append(result_array, [prevFrame])
ret, f = c.read()
if ret == True:
k = cv2.waitKey(20)
if k == 27:
Thanks for any one who tries to help me. I found the answer. Just before the While() loop we define an empty array:
then we append the curFrame into result_array by :