Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

import numpy as np import cv2

cap = cv2.VideoCapture('/Users/nimya/Desktop/people-walking2.mp4')

ret, current_frame = cap.read()

fgbg = cv2.createBackgroundSubtractorMOG2()

previous_frame = current_frame

def framediff(current_frame_gray,previous_frame_gray): frame_diff = cv2.absdiff(current_frame_gray,previous_frame_gray) cv2.imshow('frame diff ',frame_diff) return frame_diff

while(cap.isOpened()): current_frame_gray = cv2.cvtColor(current_frame, cv2.COLOR_BGR2GRAY) previous_frame_gray = cv2.cvtColor(previous_frame, cv2.COLOR_BGR2GRAY) frame_diff=framediff(current_frame_gray,previous_frame_gray)

if cv2.waitKey(1) & 0xFF == ord('q'): break previous_frame = current_frame.copy() ret, current_frame = cap.read()

cap.release() cv2.destroyAllWindows()

import numpy as np np

import cv2

cap = cv2.VideoCapture('/Users/nimya/Desktop/people-walking2.mp4')

ret, current_frame = cap.read()

fgbg = cv2.createBackgroundSubtractorMOG2()

previous_frame = current_frame

def framediff(current_frame_gray,previous_frame_gray): framediff(current_frame_gray,previous_frame_gray):

frame_diff = cv2.absdiff(current_frame_gray,previous_frame_gray)
  cv2.imshow('frame diff ',frame_diff)
  return frame_diffframe_diff

while(cap.isOpened()):

while(cap.isOpened()):

current_frame_gray = cv2.cvtColor(current_frame, cv2.COLOR_BGR2GRAY)
  previous_frame_gray = cv2.cvtColor(previous_frame, cv2.COLOR_BGR2GRAY)
    frame_diff=framediff(current_frame_gray,previous_frame_gray)

frame_diff=framediff(current_frame_gray,previous_frame_gray)

if cv2.waitKey(1) & 0xFF == ord('q'): ord('q'):

    break
  previous_frame = current_frame.copy()
  ret, current_frame = cap.read()cap.read()

cap.release()

cap.release() cv2.destroyAllWindows()

import numpy as np

import cv2

cap = cv2.VideoCapture('/Users/nimya/Desktop/people-walking2.mp4')

ret, current_frame = cap.read()

fgbg = cv2.createBackgroundSubtractorMOG2()

previous_frame = current_frame

def framediff(current_frame_gray,previous_frame_gray):

frame_diff = cv2.absdiff(current_frame_gray,previous_frame_gray)

cv2.imshow('frame diff ',frame_diff)

return frame_diff

while(cap.isOpened()):

current_frame_gray = cv2.cvtColor(current_frame, cv2.COLOR_BGR2GRAY)

previous_frame_gray = cv2.cvtColor(previous_frame, cv2.COLOR_BGR2GRAY)

frame_diff=framediff(current_frame_gray,previous_frame_gray)

if cv2.waitKey(1) & 0xFF == ord('q'):

    break

previous_frame = current_frame.copy()

ret, current_frame = cap.read()

cap.release()

cv2.destroyAllWindows()

click to hide/show revision 4
No.4 Revision

import numpy as np

import cv2

cv2

cap = cv2.VideoCapture('/Users/nimya/Desktop/people-walking2.mp4')

cv2.VideoCapture('/Users/nimya/Desktop/people-walking2.mp4')

ret, current_frame = cap.read()

cap.read()

fgbg = cv2.createBackgroundSubtractorMOG2()

cv2.createBackgroundSubtractorMOG2()

previous_frame = current_frame

current_frame def framediff(current_frame_gray,previous_frame_gray):

def framediff(current_frame_gray,previous_frame_gray):

 frame_diff = cv2.absdiff(current_frame_gray,previous_frame_gray)

 cv2.imshow('frame diff ',frame_diff)

 return frame_diff

while(cap.isOpened()):

while(cap.isOpened()):
 current_frame_gray = cv2.cvtColor(current_frame, cv2.COLOR_BGR2GRAY)

 previous_frame_gray = cv2.cvtColor(previous_frame, cv2.COLOR_BGR2GRAY)

 frame_diff=framediff(current_frame_gray,previous_frame_gray)

if cv2.waitKey(1) & 0xFF == ord('q'):

ord('q'):
     break

 previous_frame = current_frame.copy()

 ret, current_frame = cap.read()


cap.release()

cv2.destroyAllWindows()

cap.release()

cv2.destroyAllWindows()

click to hide/show revision 5
No.5 Revision

Code:

 import numpy as np

np
    import cv2

 cap = cv2.VideoCapture('/Users/nimya/Desktop/people-walking2.mp4')

 ret, current_frame = cap.read()

 fgbg = cv2.createBackgroundSubtractorMOG2()

 previous_frame = current_frame

 def framediff(current_frame_gray,previous_frame_gray):

     frame_diff = cv2.absdiff(current_frame_gray,previous_frame_gray)

     cv2.imshow('frame diff ',frame_diff)

     return frame_diff


 while(cap.isOpened()):

     current_frame_gray = cv2.cvtColor(current_frame, cv2.COLOR_BGR2GRAY)

     previous_frame_gray = cv2.cvtColor(previous_frame, cv2.COLOR_BGR2GRAY)

     frame_diff=framediff(current_frame_gray,previous_frame_gray)

 if cv2.waitKey(1) & 0xFF == ord('q'):

         break

     previous_frame = current_frame.copy()

     ret, current_frame = cap.read()


 cap.release()

 cv2.destroyAllWindows()