Beispiel #1
0
    def __init__(self, initial_frame, detector, tracker, droi, show_droi, mcdf,
                 mctf, di, cl_position):
        self.frame = initial_frame  # current frame of video
        self.detector = detector
        self.tracker = tracker
        self.droi = droi  # detection region of interest
        self.show_droi = show_droi
        self.mcdf = mcdf  # maximum consecutive detection failures
        self.mctf = mctf  # maximum consecutive tracking failures
        self.di = di  # detection interval
        self.cl_position = cl_position  # counting line position

        self.blobs = OrderedDict()
        self.f_height, self.f_width, _ = self.frame.shape
        self.frame_count = 0  # number of frames since last detection
        self.vehicle_count = 0  # number of vehicles counted
        self.types_counts = OrderedDict()  # counts by vehicle type
        self.counting_line = None if cl_position == None else get_counting_line(
            self.cl_position, self.f_width, self.f_height)

        # create blobs from initial frame
        droi_frame = get_roi_frame(self.frame, self.droi)
        _bounding_boxes, _classes, _confidences = get_bounding_boxes(
            droi_frame, self.detector)
        #print (droi_frame)
        self.blobs = add_new_blobs(_bounding_boxes, _classes, _confidences,
                                   self.blobs, self.frame, self.tracker,
                                   self.counting_line, self.cl_position,
                                   self.mcdf)
    def __init__(self, initial_frame, detector, tracker, droi, show_droi, mcdf,
                 mctf, di, cl_position):
        self.frame = initial_frame  # current frame of video
        self.detector = detector
        self.tracker = tracker
        self.droi = droi  # detection region of interest
        self.show_droi = show_droi
        self.mcdf = mcdf  # maximum consecutive detection failures
        self.mctf = mctf  # maximum consecutive tracking failures
        self.di = di  # detection interval
        self.cl_position = cl_position  # counting line position

        self.blobs = OrderedDict()
        self.blob_id = 1
        self.f_height, self.f_width, _ = self.frame.shape
        self.frame_count = 0  # number of frames since last detection
        self.vehicle_count = 0  # number of vehicles counted
        self.counting_line = None if cl_position == None else get_counting_line(
            self.cl_position, self.f_width, self.f_height)

        # create blobs from initial frame
        droi_frame = get_roi_frame(self.frame, self.droi)
        initial_bboxes = get_bounding_boxes(droi_frame, self.detector)
        for box in initial_bboxes:
            _blob = create_blob(box, frame, self.tracker)
            self.blobs[self.blob_id] = _blob
            self.blob_id += 1
# init video object and log file to record counting
if args.record:
    output_video = cv2.VideoWriter('./videos/output.avi',
                                   cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'),
                                   30, (f_width, f_height))

    log_file_name = 'log.txt'
    with contextlib.suppress(FileNotFoundError):
        os.remove(log_file_name)
    log_file = open(log_file_name, 'a')
    log_file.write('vehicle_id, count, datetime\n')
    log_file.flush()

# set counting line
clposition = 'bottom' if args.clposition == None else args.clposition
counting_line = get_counting_line(clposition, f_width, f_height)
vehicle_count = 0

# create detection ROI
droi = [(0, 0), (f_width, 0), (f_width, f_height), (0, f_height)]
if args.droi:
    droi = []
    points = args.droi.replace(' ', '').split('|')
    for point_str in points:
        point = tuple(map(int, point_str.split(',')))
        droi.append(point)

# initialize trackers and create new blobs
droi_frame = get_roi_frame(frame, droi)
initial_bboxes = get_bounding_boxes(droi_frame, detector)
for box in initial_bboxes:
Beispiel #4
0
    def __init__(self, initial_frame, detector, tracker, droi, show_droi, mcdf, mctf, di, cl_position):
        ha = os.path.join('detect-and-count-object','detectors')
        path = os.path.join(ha,'yolo')
        labelsPath = os.path.join(path,'coco.names')
        LABELS = open(labelsPath).read().strip().split("\n")

        self.frame = initial_frame # current frame of video

        self.detector = detector

        self.tracker = tracker

        self.droi =  droi # detection region of interest

        self.show_droi = show_droi

        self.mcdf = mcdf # maximum consecutive detection failures

        self.mctf = mctf # maximum consecutive tracking failures

        self.di = di # detection interval

        self.cl_position = cl_position # counting line position


        self.countCar = 0
        self.countTruck = 0
        self.countBus = 0
        self.countPerson = 0
        self.countBicycle = 0
        self.countMotorcycle = 0

        self.blobs = OrderedDict()

        self.blob_id = 1

        self.f_height, self.f_width, _ = self.frame.shape

        self.frame_count = 0 # number of frames since last detection

        self.vehicle_count = 0 # number of vehicles counted

        self.counting_line = get_counting_line(self.cl_position, self.f_width, self.f_height)



        # create blobs from initial frame

        droi_frame = get_roi_frame(self.frame, self.droi)

        initial_bboxes = get_bounding_boxes(droi_frame, self.detector)
        
        for box in initial_bboxes:
            #print(box)
            if self.detector == 'yolo':
                _blob = create_blob(box[0], frame, self.tracker)
                style = LABELS[box[1][0]]
                self.blobs[self.blob_id] = _blob, style
                self.blob_id += 1
            else:
                _blob = create_blob(box, frame, self.tracker)
                self.blobs[self.blob_id] = _blob
                self.blob_id += 1