# grab the frame from the threaded video stream and resize it
 # to have a maximum width of 400 pixels
 frame = vs.read()
 lastUploaded = datetime.datetime.now()
 #saveFrame = frame                       # For storing a copy for encoding later on.
 frame = cv2.resize(frame, (500, 500))
 counter = 0
 # At 400 width we get a real nice frames per second, increasing
 # the value will result in less frames being read per second.
 #instance = vs.getGrabbed()
 #cascades.faceCascadeDetectionOfImage(instance)
 timestamp = 0
 # So now we store the grayFrame seperately aside from our regular colored
 # frame so we can perform processing on the grayframe since many open cv
 # operations are dependent upon a grayscaled image.
 grayFrame = filters.grayScaleImage(frame)
 # May need to take this line out.
 #grayFrame = cv2.GaussianBlur(grayFrame, (21, 21), 0)
 
 # We should add a guassian blur here to reduce noise.
 #grayFrame = filters.gaussianBlurApplying(frame)
 
 # We grayscaled it so we can apply the laplacian variance on the grayscaled
 # frame.
 fm = blurDetection.variance_of_laplacian(grayFrame)
 text = "Not Blurry"
 
 # if the focus measure is less than the supplied threshold,
 # then the image should be considered "blurry"
 
 if fm < blurDetection.getBlurThresh():
motion = MotionDetection()

destroyWindows = WindowDestruction()

firstFrame = None

while True:
    # grab the frame from the threaded video stream and resize it
    # to have a maximum width of 400 pixels
    frame = vs.read()
    #saveFrame = frame                       # For storing a copy for encoding later on.
    #frame = cv2.resize(frame, (500, 500))

# If the WebcamVideoStream object has a frame grabbed, lets perform operations.
if (vs.grabbed):
        gray = filters.grayScaleImage(frame)
        gray = filters.gausBlurSpecified(gray, 21, 21)
        # originally our dimensions for gaussian blur is 21 by 21
         
        # if the first frame is None, initialize it
        '''if (cv2.waitKey(20) & 0xFF == ord('r')):    # If r is pressed we want to refresh frame to
            firstFrame = gray
            continue
        else:
            firstFrame = gray
            continue'''
        if firstFrame is None:
            firstFrame = gray
            continue

        # compute the absolute difference between the current frame and