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
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:
    _blob = create_blob(box, frame, tracker)
    blobs[blob_id] = _blob
    blob_id += 1

while True:
    k = cv2.waitKey(1)
    if args.iscam or cap.get(cv2.CAP_PROP_POS_FRAMES) + 1 < cap.get(
            cv2.CAP_PROP_FRAME_COUNT):
        _, frame = cap.read()

        nframes = cap.get(cv2.CAP_PROP_POS_FRAMES)
        frame_count = cap.get(cv2.CAP_PROP_FRAME_COUNT)
        if nframes % 10 == 0 or nframes == 1:
            print("Processing {} of {} frames".format(nframes, frame_count))

        for _id, blob in list(blobs.items()):
Beispiel #3
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