Home > Software design >  Can I do it with histogram (frequency distribution)?
Can I do it with histogram (frequency distribution)?

Time:11-08

I have extracted the frames from video and converted into the optical flow looks like this;

enter image description here

You can clearly see that there are some frames that are giving information of an moving object (frame000037, frame000039, so on) and some are static (frame000038, frame000040, frame000042, so on).

I have read both frames static one and moving one to see the differences using OpenCV, Can anyone tell me who can I filter out those all frames that contains the motion information?

I have taken mean, standard deviation, normalization, but they didn't worked for me as the pixels value can be greater for the static than movable and in some from it can be less than the movable therefore it didn't work for every case.

CodePudding user response:

You can np.sum white pixels of each frame and use results as weight. Your empty frame result will be constant , equal to the area of the frame. So you can check if the frame is empty or not .

import cv2
import numpy as np

img1=cv2.imread("/tmp/frame0.bmp",0)
img2=cv2.imread("/tmp/frame1.bmp",0)

th = 150

ret, m1 = cv2.threshold(img1,th,255,cv2.THRESH_BINARY_INV)
ret, m2 = cv2.threshold(img2,th,255,cv2.THRESH_BINARY_INV)

n_pix1 = np.sum(m1 == 255)
n_pix2 = np.sum(m2 == 255)

print(n_pix1,n_pix2)


cv2.imshow("1",m1)
cv2.imshow("2",m2)

cv2.waitKey(0)

enter image description here

  • Related