def main():
    # Construct the argument parse and parse the arguments
    ap = argparse.ArgumentParser()
    ap.add_argument("-m", "--model", required=True,
                    help="path to model file")
    ap.add_argument("-c", "--confidence", type=float, default=0.95,
                    help="minimum probability to filter weak detections")
    args = vars(ap.parse_args())

    # Initialize our centroid tracker and frame dimensions
    ct = CentroidTracker()

    # Load our serialized model from disk
    print("[INFO] Loading model...")
    model = get_model(args["model"])

    vs = FileVideoStream("/media/ave/ae722e82-1476-4374-acd8-a8a18ef8ae7a/Rana_vids/Nova_1/121/03-2018.05.25_06.24.23-17.mpg").start()
    time.sleep(2.0)

    # Loop over the frames from the video stream
    while vs.more():
        # Read the next frame from the video stream
        frame = vs.read()

        analyze_frame(frame, ct, model, args["confidence"])

    # Cleanup
    cv2.destroyAllWindows()
    vs.stop()
Ejemplo n.º 2
0
 def __init__(self, video_capture, czones):
     self.czones = czones
     self.fps = int(video_capture.get(cv2.CAP_PROP_FPS))
     self.cap = video_capture
     self.ct = CentroidTracker(maxDisappeared=8)
     self.mapped_centroid_classes = {}
     self.tracked_objects_status = {}
     self.frameid_control = {}
     self.estimated_speed = {}
Ejemplo n.º 3
0
def main(args):
    # Read video
    frames, fps = read_video(args.video_path)
    print(f"Read {len(frames)} frames (fps: {fps})")

    # Read bboxes of each frame
    json_files = sorted(os.listdir(args.bbox_path),
                        key=lambda x: int(x.split(".")[0]))
    object_boxes_per_frame = []

    for file in json_files:
        with open(os.path.join(args.bbox_path, file)) as f:
            data = json.load(f)
            bboxes = data['children'].copy()
            object_boxes_per_frame.append(bboxes)
    print(f"Read {len(object_boxes_per_frame)} bbox files")

    # Run object tracking
    centroid_ids_per_frame = []

    if args.method == "centroid":
        ct = CentroidTracker(maxDisappeared=50)

        for ind in range(len(frames)):
            rects = [[obj['x1'], obj['y1'], obj['x2'], obj['y2']]
                     for obj in object_boxes_per_frame[ind]]
            centroid_ids = ct.update(rects)
            centroid_ids_per_frame.append(centroid_ids.copy())

    elif args.method == "kalman":
        tracker = Sort(max_age=50, min_hits=3)

        for ind in range(len(frames)):
            detections = np.array([[
                obj['x1'], obj['y1'], obj['x2'], obj['y2'], obj['confidence']
            ] for obj in object_boxes_per_frame[ind]])
            trackers = tracker.update(detections, None)
            centroid_ids = [[((track[0] + track[2]) / 2,
                              (track[1] + track[3]) / 2),
                             int(track[4])] for track in trackers]
            centroid_ids_per_frame.append(centroid_ids)
    else:
        raise NotImplementedError
    print(f"Processed {len(centroid_ids_per_frame)} frames")

    # Create output video
    annotated_frames = annotate_frames(frames, object_boxes_per_frame,
                                       centroid_ids_per_frame)
    frames2video(annotated_frames, fps=28, filepath=args.save_path)
    print("Created output video")
    def __init__(self):
        # Instantiate detector
        self.detector = ObjectDetection()

        # Set and load model
        self.model_path = "D:/Final-Year-Project/Object-tracking/models/yolo.h5"
        self.detector.setModelTypeAsYOLOv3()
        self.detector.setModelPath(self.model_path)
        self.detector.loadModel()

        # Set custom objects
        self.custom_objects = self.detector.CustomObjects(car=True,
                                                          motorcycle=True,
                                                          person=True,
                                                          bicycle=True,
                                                          dog=True)
        self.tracker = CentroidTracker()
Ejemplo n.º 5
0
    def __init__(self, publisher: mqtt_publisher, args):
        # Start Arguments
        self.publisher: mqtt_publisher = publisher

        for k, v in args.items():
            if k is "skip_frame":
                if v is not None:
                    self.skip_frame = int(v)
                else:
                    self.skip_frame = 5
            if k is "min_confidence":
                if v is not None:
                    self.min_confidence = float(v)
                else:
                    self.min_confidence = 0.4
            if k is "resolution":
                if v is not None:
                    w, h = v.split(",")
                    self.resolution = (int(w), int(h))
                else:
                    self.resolution = (640, 480)
            if k is "debug":
                if v is not None:
                    self.debug = v
                else:
                    self.debug = False

        # Classes the net Model recognises
        self.CLASSES = ["background", "aeroplane", "bicycle", "bird", "boat",
                        "bottle", "bus", "car", "cat", "chair", "cow", "diningtable",
                        "dog", "horse", "motorbike", "person", "pottedplant", "sheep",
                        "sofa", "train", "tvmonitor"]

        # centroid tracker and some inits
        self.ct = CentroidTracker(publisher, maxDisappeared=40, maxDistance=50, )
        self.targets = []
        self.rois = OrderedDict()
        self.take_snap = False
        self.fps = None
        self.s = sched.scheduler(time.time, time.sleep)
Ejemplo n.º 6
0
    def __init__(self,
                 camera_idx,
                 camera_view,
                 res_x=640,
                 res_y=480,
                 view_h=450,
                 view_w=800,
                 origin_distance=0,
                 static_background=None):
        """
            camera_idx: refers to the device number
            camera_view: can either be "TOP-DOWN" or "FRONT-ON"
            res_x: refers to camera's horisontal resolution
            res_x: refers to camera's vertical resolution
            view_h: height of the camera view window
            view_w: width of the camera view window
            origin_distance: distance between camera and origin in cm
            static_background: background for which newly drawn frames are
                               diffed against for detecting objects
        """

        self.cam = cv2.VideoCapture(camera_idx)
        self.cam.set(cv2.CAP_PROP_FRAME_HEIGHT, view_h)
        self.cam.set(cv2.CAP_PROP_FRAME_WIDTH, view_w)

        # where the camera view
        self.camera_view = camera_view
        assert (self.camera_view == "TOP-DOWN" or "FRONT-ON")

        self.res_x = res_x
        self.res_y = res_y

        self.origin_distance = origin_distance
        self.pixel_cm_ratio = 0

        self.static_background = static_background
        self.centroid_tracker = CentroidTracker()
Ejemplo n.º 7
0
def process_image(img, img_index):
    # get an image from 'img' directory
    template = cv2.imread("./ball-img/{}".format(imgs[img_index]))

    # original image to draw rectangles on
    og_img = img

    # define region of interest
    roi_xy1 = (450, 219)
    roi_xy2 = (830, 549)
    img = img[roi_xy1[1]:roi_xy2[1], roi_xy1[0]:roi_xy2[0]]

    # make the image easier to work with
    #img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    #img = cv2.GaussianBlur(img, (11, 11), 0)
    #img = getCanny(img)
    """
    # find circles
    circles = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1.2, 10)
    # ensure at least some circles were found
    if circles is not None:
	# convert the (x, y) coordinates and radius of the circles to integers
        circles = np.round(circles[0, :]).astype("int")

        # loop over the (x, y) coordinates and radius of the circles
        for (x, y, r) in circles:
            # draw the circle in the output image, then draw a rectangle
            # corresponding to the center of the circle
            cv2.circle(og_img, (x + roi_xy1[0], y + roi_xy1[1]), r, (0, 255, 0), 4)
            cv2.rectangle(og_img, (x - 5 + roi_xy1[0], y - 5 + roi_xy1[1]), (x + 5 + roi_xy1[0], y + 5 + roi_xy1[1]), (0, 128, 255), -1)
    """

    # find matches
    minimized = False
    try:
        img = cv2.matchTemplate(template, img, cv2.TM_CCOEFF_NORMED)
    except Exception as ex:
        minimized = True
        print("The window cannot be minimized...")

    # wait until user reopens window
    while minimized:
        try:
            img = screen_cap(hwnd=hwnd)
            img = cv2.matchTemplate(template, img, cv2.TM_CCOEFF_NORMED)
        except Exception as ex:
            pass
        else:
            print("Resuming...")
            sleep(1)
            break

    # get location and confidence
    min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(img)

    # only draw rectangle and calc location if the confidence is greater than 0.6
    if max_val > 0.65:
        # convert location to be relative to og_img
        top_left = (max_loc[0] + roi_xy1[0], max_loc[1] + roi_xy1[1])
        bottom_right = (top_left[0] + template.shape[1],
                        top_left[1] + template.shape[0])

        # object tracking with centroid_tracker
        ct = CentroidTracker()
        (H, W) = (None, None)

        cv2.rectangle(og_img,
                      top_left,
                      bottom_right,
                      color=(0, 0, 255),
                      thickness=2,
                      lineType=cv2.LINE_4)

        print("Ball location: ", max_loc)
        print("Confidence: ", max_val)

    return og_img
Ejemplo n.º 8
0
def playback():
    # handle each group separately, good for making DB
    for cams, group_name, fps in cams_groups:
        # delete everything we know
        tracked_objects.clear()
        tracked_objects_reid.clear()
        if config.keep_track_targeted:
            build_known_people()

        players = [
            PicturePlayback(camera, fps, not config.playback_realtime)
            for camera in cams
        ]
        # players = [CameraPlayback()]
        # player = [VideoPlayback('video.avi')]
        # players = [YoutubePlayback('https://www.youtube.com/watch?v=N79f1znMWQ8')]

        # centroid tracker for each camera to keep track of IDs after new detection
        centroid_tracker = [
            CentroidTracker(0, config.centroid_max_distance)
            for _ in range(len(cams))
        ]
        correlation_trackers = [[] for _ in range(len(cams))]

        # start playback
        for player in players:
            player.start()

        frame_index = 0
        while any([player.is_playing() for player in players]):
            frames = [player.get_frame() for player in players]
            # make them all to have the same length
            # current frame for each camera
            for camera_i, frame in enumerate(frames):
                if frame is None:
                    continue
                # rectangles of detected people in current frame
                frame_copy = frame.copy()
                bodies = []
                # should we try detecting again?
                should_detect = (frame_index % config.detect_frequency == 0)
                if should_detect:
                    # detect rectangles
                    bodies = detect.detect_people(frame)
                    correlation_trackers[camera_i] = build_trackers(
                        bodies, frame)
                else:
                    # track rectangles
                    for tracker in correlation_trackers[camera_i]:
                        tracker.update(frame)
                        pos = tracker.get_position()
                        bodies.append((int(pos.left()), int(pos.top()),
                                       int(pos.right()), int(pos.bottom())))
                # get rectangles with IDs assigned to them
                detected_objects = centroid_tracker[camera_i].update(
                    bodies, should_detect)
                for (track_id, (x1, y1, x2, y2)) in detected_objects.items():
                    # should face and body samples be saved from the current frame?
                    should_sample = (frame_index %
                                     config.detect_frequency == 0)
                    # should we try to find match for newly detected people with known people?
                    should_reid_known = (frame_index % config.detect_frequency
                                         == 0) and len(known_objects) > 0
                    # should we try to find match for newly detected people?
                    should_reid = (frame_index % config.detect_frequency == 0)
                    # TODO: clear these checks
                    # fix out of image
                    x2, x1, y2, y1 = min(x2, frame.shape[1]), max(x1, 0), min(
                        y2, frame.shape[1]), max(y1, 0)
                    # too small, ignore
                    if x2 - x1 < 10 or y2 - y1 < 20:
                        continue
                    # convert from internal track_id to actual person_id
                    while True:
                        new_id = tracked_objects_reid.get(track_id, None)
                        if new_id is None:
                            break
                        track_id = new_id

                    person_track = tracked_objects.get(track_id, None)
                    if person_track is None:
                        person_track = known_objects.get(track_id, None)

                    cropped_body = frame[y1:y2, x1:x2]

                    if person_track is None:
                        if should_detect:
                            logging.info(
                                'PLAYBACK: new person {} detected in camera {}'
                                .format(track_id, camera_i))
                        person_track = PersonTrack(track_id, n_cameras)
                        tracked_objects[track_id] = person_track
                        # sample for re-ID
                        should_sample = True
                        # try to find whether we have seen this person before
                        should_reid = True
                    elif should_detect:
                        # compare to self just in case it's actually a new person
                        if config.reid_same:
                            test_id = centroid_tracker[camera_i].next_id
                            test_track = PersonTrack(test_id, n_cameras)
                            test_track.add_body_sample(cropped_body,
                                                       frame_index, camera_i)
                            face = detect.get_face(cropped_body)
                            if face is not None:
                                test_track.add_face_sample(
                                    face, frame_index, camera_i)
                            self_compare = recognize.compare_to_detected(
                                test_track, {track_id: person_track})
                            # same centroid but persons don't match
                            if self_compare is None:
                                # re-id this centroid because i'ts not the same person
                                centroid_tracker[camera_i].reid(
                                    track_id, test_id)
                                CentroidTracker.next_id += 1

                                tracked_objects[test_id] = test_track
                                track_id = test_id
                                person_track = test_track

                                logging.info(
                                    'PLAYBACK: new person {} detected in camera {}'
                                    .format(track_id, camera_i))

                                should_sample = False
                                should_reid = True
                        # TODO: re-IDed person should be re-IDed again, because A1==A2 =never match= B1==B2
                        # don't re-ID people who were re-IDed before, so there are no cycles in detection
                        should_reid = should_reid and not person_track.was_reided(
                        )
                        should_reid_known = should_reid_known and not person_track.is_known(
                        )

                    if should_sample:
                        person_track.add_body_sample(cropped_body, frame_index,
                                                     camera_i)
                        # try to find face of this person
                        face = detect.get_face(cropped_body)
                        if face is not None:
                            person_track.add_face_sample(
                                face, frame_index, camera_i)
                    compare_to_array = []
                    if should_reid_known:
                        compare_to_array.append(
                            (known_objects,
                             config.known_required_match_percent))
                    if should_reid:
                        compare_to_array.append(
                            (tracked_objects, config.required_match_percent))
                    for compare_to, required_match in compare_to_array:
                        same_person_id = recognize.compare_to_detected(
                            person_track, compare_to, required_match)
                        if same_person_id is not None and same_person_id != track_id:
                            # get track of person we matched
                            same_person_track = compare_to.get(same_person_id)
                            # merge information
                            same_person_track.merge(person_track)
                            # we only need one track, the one that doesn't have less information
                            tracked_objects.pop(track_id)
                            # re-ID from trackers ID to person ID
                            tracked_objects_reid[track_id] = same_person_id
                            # update values
                            track_id = same_person_id
                            person_track = same_person_track
                            person_track.reid()
                            break
                        elif same_person_id == track_id:  # this is an error and should never happened :)
                            logging.error(
                                'PLAYBACK: comparing and matching same person {}, something is wrong'
                                .format(track_id))
                        # we do not keep track of this person, delete him
                        # TODO: creating the instance is quite unnecessary, but not 'that' costly...
                        if not config.keep_track_all and not person_track.is_known(
                        ):
                            del tracked_objects[track_id]

                    # display information on screen
                    # TODO: maybe add face? but tracking it is unnecessary and we detect in irregularly, so probably not
                    cv2.rectangle(frame_copy, (x1, y1), (x2, y2), (255, 0, 0),
                                  1)
                    cv2.putText(frame_copy, person_track.get_name(), (x1, y1),
                                cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2,
                                cv2.LINE_AA)

                cv2.imshow('Camera {}'.format(camera_i), frame_copy)

            # TODO: better quitting but it's OK for now
            if cv2.waitKey(1) & 0xFF == ord('q'):
                break

            frame_index += 1

        cv2.destroyAllWindows()

        # build database from collected information
        if config.build_dataset:
            improve.build_new_dataset(group_name, tracked_objects)

    logging.info('PLAYBACK: Playback finished')
Ejemplo n.º 9
0
from imutils.video import VideoStream
import numpy as np
import argparse
import time
import cv2

ap = argparse.ArgumentParser()
ap.add_argument("-p", "--prototxt", default="face_model/deploy.prototxt", \
    help="path to Caffe prototxt file")
ap.add_argument("-m", "--model", default="face_model/res10_300x300_ssd_iter_140000.caffemodel",\
     help="path to Caffe pre-trained model")
ap.add_argument("-c", "--confidence", type=float, default=0.5,\
    help="detection threshold")
args = vars(ap.parse_args())

cent_tracker = CentroidTracker()
(H, W) = (None, None)

print("loading the model")
net = cv2.dnn.readNetFromCaffe(args["prototxt"], args["model"])

print("start video streaming")
vs = VideoStream(src=0).start()
# to warm up the camera, wait 2.0 sec
time.sleep(2.0)

while True:
    frame = vs.read()
    frame = imutils.resize(frame, width=400)

    # this statement is used for the initializer step
import time

from annotation import Annotator

import numpy as np
import picamera

from PIL import Image
from tflite_runtime.interpreter import Interpreter

import dlib

CAMERA_WIDTH = int(640 / 2)
CAMERA_HEIGHT = int(480 / 2)

ct = CentroidTracker()


def load_labels(path):
    """Loads the labels file. Supports files with or without index numbers."""
    with open(path, 'r', encoding='utf-8') as f:
        lines = f.readlines()
        labels = {}
        for row_number, content in enumerate(lines):
            pair = re.split(r'[:\s]+', content.strip(), maxsplit=1)
            if len(pair) == 2 and pair[0].strip().isdigit():
                labels[int(pair[0])] = pair[1].strip()
            else:
                labels[row_number] = pair[0].strip()
    return labels
Ejemplo n.º 11
0
def main():
    ct = CentroidTracker(10)
    pub.subscribe(face_out_of_frame, 'face_out_of_frame')
    pub.subscribe(face_in_frame, 'face_in_frame')
    log.basicConfig(format="[ %(levelname)s ] %(message)s",
                    level=log.INFO,
                    stream=sys.stdout)
    args = build_argparser().parse_args()
    stream = cv2.VideoCapture(0)
    model_bin, model_xml = get_face_detection_model(args)
    model_age_gender_xml, model_age_gender_bin = get_age_gender_detection_model(
        args)
    # Plugin initialization for specified device and load extensions library if specified
    plugin = get_plugin(args)
    print('running on device', args.device)
    add_extension_to_plugin(args, plugin)
    face_detection_net = IENetwork(model=model_xml, weights=model_bin)
    check_for_unsupported_layers(plugin, face_detection_net)
    age_gender_net = IENetwork(model=model_age_gender_xml,
                               weights=model_age_gender_bin)
    check_for_unsupported_layers(plugin, age_gender_net)
    # /opt/intel/computer_vision_sdk/deployment_tools/intel_models/face-detection-adas-0001/FP32/face-detection-adas-0001.xml

    log.info("Preparing inputs")
    face_net_input_blob = next(iter(face_detection_net.inputs))
    face_net_output_blob = next(iter(face_detection_net.outputs))
    face_detection_net.batch_size = 1

    # Read and pre-process input images
    n, c, h, w = face_detection_net.inputs[face_net_input_blob].shape
    print('number of images :', n, 'number of channels:', c,
          'height of image:', h, 'width of image:', w)
    # Loading model to the plugin
    log.info("Loading model ton the plugin")
    exec_net = plugin.load(network=face_detection_net)
    age_gender_input_blob = next(iter(age_gender_net.inputs))
    # print(face_detection_net.inputs,face_detection_net.outputs,age_gender_net.inputs,age_gender_net.outputs)
    # print(age_gender_net.outputs,len(age_gender_net.outputs))
    age_blob = 'age_conv3'
    gender_blob = 'prob'

    age_output = age_gender_net.outputs[age_blob]
    gender_output = age_gender_net.outputs[gender_blob]
    print("age,gender,model input specs",
          age_gender_net.inputs[age_gender_input_blob].shape)
    agen, agec, ageh, agew = age_gender_net.inputs[age_gender_input_blob].shape
    print("loading page gender model to the plugin")
    exec_age_gender_net = plugin.load(network=age_gender_net)

    while (True):
        status, image = stream.read()
        res, initialw, initialh = infer_face(n, c, h, w, image, exec_net,
                                             face_net_input_blob)
        out = res[face_net_output_blob]
        count = 0

        tfaces = np.ndarray(shape=(agen, agec, ageh, agew))
        rects = []
        for obj in out[0][0]:
            threshold = obj[2]
            class_id = int(obj[1])
            if threshold > 0.9:
                count = count + 1
                xmin = int(obj[3] * initialw)
                ymin = int(obj[4] * initialh)
                xmax = int(obj[5] * initialw)
                ymax = int(obj[6] * initialh)
                color = (min(class_id * 12.5,
                             255), min(class_id * 7,
                                       255), min(class_id * 5, 255))
                face = image[ymin:ymax, xmin:xmax]
                (fh, fw) = face.shape[:-1]
                if fh < ageh or fw < agew:
                    continue
                tface = cv2.resize(face, (agew, ageh))
                tface = tface.transpose((2, 0, 1))
                tfaces[0] = tface
                t0 = time()
                out_age_gender = exec_age_gender_net.infer(
                    inputs={face_net_input_blob: tfaces})
                print('inferencetime age,gender detection',
                      (time() - t0) * 1000)
                age, gender, checkedin = get_age_gender(
                    out_age_gender, age_blob, gender_blob)

                rects.append((xmin, ymin, xmax, ymax, age, gender, checkedin))

                cv2.rectangle(image, (xmin, ymin), (xmax, ymax), color, 2)

        print("number of faces in frame", count)
        if count > 0:
            x = ct.update(rects)
            print(list(x.items()))
            cv2.imshow("face", face)

        cv2.imshow("Display", image)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
        return cap.isOpened() if args.video_path != '' else True

    def get_frame():
        if args.video_path != '':
            return cap.read()
        else:
            in_Frame = qOut_Frame.get()
            frame = in_Frame.getCvFrame()
            return True, frame

    startTime = time.monotonic()
    detections = []
    frame_count = 0
    counter = [0, 0, 0, 0]  # left, right, up, down

    ct = CentroidTracker(maxDisappeared=40, maxDistance=50)
    trackableObjects = {}

    def to_planar(arr: np.ndarray, shape: tuple) -> np.ndarray:
        return cv2.resize(arr, shape).transpose(2, 0, 1).flatten()

    while should_run():
        # Get image frames from camera or video file
        read_correctly, frame = get_frame()
        if not read_correctly:
            break

        if args.video_path != '':
            # Prepare image frame from video for sending to device
            img = dai.ImgFrame()
            img.setData(to_planar(frame, (300, 300)))
Ejemplo n.º 13
0
                        dest='start_offset',
                        type=int,
                        default=0,
                        help='Start time in seconds.')

    args = parser.parse_args()

    cap = cv2.VideoCapture(args.video_source)
    cap.set(cv2.CAP_PROP_FRAME_WIDTH, args.width)
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT, args.height)
    cap.set(cv2.CAP_PROP_POS_MSEC, args.start_offset * 1000)

    folder_output = args.folder_output
    if not os.path.exists(folder_output):
        os.makedirs(folder_output)
    ct = CentroidTracker(folder_output)

    start_time = datetime.datetime.now()
    num_frames = 0
    im_width, im_height = (cap.get(3), cap.get(4))
    print("Image Width: ", im_width)
    print("Image Height: ", im_height)
    # max number of hands we want to detect/track
    num_hands_detect = 4

    cv2.namedWindow('Single-Threaded Detection', cv2.WINDOW_NORMAL)

    while True:
        # Expand dimensions since the model expects images to have shape: [1, None, None, 3]
        ret, image_np = cap.read()
Ejemplo n.º 14
0
RESIZED_HEIGHT = int(FRAME_HEIGHT * RESIZE_SCALAR)
TRACKER_REACQUISITION_RANGE = int(settings.trackrange * RESIZE_SCALAR)
TRACKER_REACQUISITION_TIME = settings.tracktime
DEBUG_MODE = settings.debug
CAPTURE_FRAMERATE = settings.framerate  # This is a framerate of the .avi recording

# Start the stopwatch / counter
t1_start = process_time()

# Initialize the heads up display controller which draws the UI on top of the frame
hud = HUDController(success_area_y=settings.success_area_y,
                    success_area_length=settings.success_area_length,
                    frame_width=RESIZED_WIDTH)

# Initialize the centroid tracker which keeps track of the same balls between frames
ct = CentroidTracker(TRACKER_REACQUISITION_RANGE, TRACKER_REACQUISITION_TIME)

# Initialize the height checker and desired starting height boundary
starting_y = FRAME_HEIGHT / 4 * RESIZE_SCALAR
starting_height = FRAME_HEIGHT / 10 * RESIZE_SCALAR

# Load Yolo
net = cv2.dnn.readNet("../yolo/yolov3_training.weights",
                      "../yolo/yolov3_config.cfg")

# Enable GPU processing
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_CUDA)
net.setPreferableTarget(cv2.dnn.DNN_TARGET_CUDA)

# Name custom object
classes = ["juggling ball"]
Ejemplo n.º 15
0
# dict.get(key, return value if the specified key doesn't exit)
# which means if "input" is None, it will return False
if not args.get("input", False):
    print("starting video stream")
    vs = VideoStream(src=0).start()
    # webcam warmup time
    time.sleep(2.0)
else:
    print("opening the specified video file")
    vs = cv2.VideoCapture(args["input"])

writer = None
W = None
H = None

cent_tracker = CentroidTracker(max_frames_to_disappear=40, max_distance=50)
trackers = []
trackable_objs_dict = {}

total_frames = 0
total_downs = 0
total_ups = 0

fps = FPS().start()

while True:
    frame = vs.read()
    frame = frame[1] if args.get("input", False) else frame

    # if the optinal input is set and the obtained frame is None,
    # it means the frame reached at the end of the video