def __init__(self): # If video source is USB device for testing, we will use the vs and cap variables below. #self.vs = WebcamVideoStream(src=0).start() # so we want to read video in as a stream now so we can self.capture = cv2.VideoCapture(0) # CHANGE MILES # 0 for drone, # 1 for webcam in the case of Miles computer # If video source is drone, we will use the code below. self.fourcc = cv2.cv.CV_FOURCC(*'XVID') self.out = cv2.VideoWriter('output.mov', self.fourcc, 20.0, (640, 480)) # So we want to open application for video driver first, and then run file. # Currently the webcam video stream class does not work for video capture, therefore we # need to stick to cv2.VideoCapture() until WebcamVideoStream can be optimized for working. # Instantiate objects self.filters = Filters() # Filters for filtering the file. self.motionDetection = MotionDetection( ) # MotionDetection for grabbing motion. self.cascadeDetection = Cascading( ) # Cascading for feature recognition. self.blurDetection = DetectBlur( 150) # 100 would be the value to be used for fine tuning. self.destroyWindows = WindowDestruction() time.sleep(0.25) # Allow camera a few miliseconds for booting up. self.firstFrame = None # First frame is a variable to be used for motion tracking, firstFrame is the frame being compared for motion change. # Initiate toggles. self.motionTime = False self.cascadeTime = False self.blurDetectionTime = False # Initialize external variables. self.numFrames = 0 self.ts = time.time()
# import the necessary packages import datetime import time import cv2 from WindowDestruction import WindowDestruction from WebcamVideoStream import WebcamVideoStream import numpy as np from MotionDetection import MotionDetection from Cascading import Cascading motion = MotionDetection() destroyWindows = WindowDestruction() cascades = Cascading() # camera = cv2.VideoCapture(0) camera = WebcamVideoStream(src=0).start() time.sleep(0.25) # initialize the first frame in the video stream # WE WILL WANT TO UPDATE THIS VARIABLE TO OFTEN CHANGE THE FIRST FRAME # BASED ON MOVEMENT OF MOTION...WILL BE TRICKY. cascadeTime = False # loop over the frames of the video while True: # grab the current frame and initialize the occupied/unoccupied # text frame = camera.read() #saveFrame = frame # For storing a copy for encoding later on. frame = cv2.resize(frame, (500, 500)) #(grabbed, frame) = camera.read()
import cv2 import numpy as np import time import datetime from Cascading import Cascading from Detect_Blur import DetectBlur blurDetection = DetectBlur(140) cascade = Cascading() #capture = cv2.VideoCapture(0) # Load video feed, we can also load a video from the directory if we wanted too, all we would do is place the path to the directory in here instead of the 0. capture = cv2.VideoCapture('testFlight.MP4') # Loading a actual video. # Will need to change directory for future testing, unless files are in same directory path. fgbg = cv2.BackgroundSubtractorMOG2() # The foreground for objects we want, we will subtract those from the actual background. # Define size of video for reading in size = (int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)), int(capture.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT))) # Define FPS fps = 20 #fourcc = cv2.cv.CV_FOURCC(*'XVID') fourcc = cv2.cv.CV_FOURCC('m', 'p', '4', 'v') #vout = cv2.VideoWriter() #success = vout.open('output.mov', fourcc, fps, size, True) #out = cv2.VideoWriter('output.avi', fourcc, 20.0, (640, 480)) ts = time.time() counter = 0 while True: ret, frame = capture.read() # Load the file into our boolean, then asssign it to a frame object.