Exemplo n.º 1
0
    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()
Exemplo n.º 2
0
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.
# For this program I'm testing the use of thresholding by applying different filters
# and seeing how easy it is to detect corners and objects within the camera frame.

ap = argparse.ArgumentParser()
ap.add_argument("-c",
                "--conf",
                required=True,
                help="path to the json configuration file")
args = vars(ap.parse_args())

vs = WebcamVideoStream(
    src=0).start()  # so we want to read video in as a stream now so we can
#cap = cv2.VideoCapture(0)
filters = Filters()
cascades = Cascading()
blurDetection = DetectBlur(120)
imgCmpr = ImageCompression()

conf = json.load(open(args["conf"]))  # Load the json file.
client = None

# check to see if the Dropbox should be used
if conf["use_dropbox"]:
    # connect to dropbox and start the session authorization process
    flow = DropboxOAuth2FlowNoRedirect(conf["dropbox_key"],
                                       conf["dropbox_secret"])
    print "[INFO] Authorize this application: {}".format(flow.start())
    authCode = raw_input("Enter auth code here: ").strip()

    # finish the authorization and grab the Dropbox client
    (accessToken, userID) = flow.finish(authCode)