Closed sbmalik closed 5 years ago
I am trying to grab previous frame of video stream because i am using the hogdetector and want to only update the result when len(rects) > 0 or len(rects) == 0, if length of rects remain same then there is no need to update result(display) or print. I want to grab the previous frame and want to compare it with current frame so i can check either length of rects changed or not.
I don't think so there is a single function/method available from OpenCV which can give you previous frame., but what you can do is store the frame while reading it so that you can use it later. But if you come across something else kindly share that as well.
e.g.
cap = cv2.VideoCapture(add your input source here)
ret, frame = cap.read()
while(cap.isOpened():
prev_frame = frame
ret, frame = cap.read()
if not ret:
break
whatever you want to do with it...
This sounds like the perfect use case for the deque
data structure. Example can be found here:
https://www.pyimagesearch.com/2015/09/21/opencv-track-object-movement/
I am trying to grab previous frame of video stream because i am using the hogdetector and want to only update the result when len(rects) > 0 or len(rects) == 0, if length of rects remain same then there is no need to update result(display) or print. I want to grab the previous frame and want to compare it with current frame so i can check either length of rects changed or not.