def count(self, frame): self.frame = frame blobs_list = list(self.blobs.items()) # update blob trackers blobs_list = Parallel(n_jobs=NUM_CORES, prefer='threads')( delayed(update_blob_tracker)(blob, blob_id, self.frame) for blob_id, blob in blobs_list) self.blobs = dict(blobs_list) for blob_id, blob in blobs_list: # count vehicle if it has crossed a counting line blob, self.counts = attempt_count(blob, blob_id, self.counting_lines, self.counts) self.blobs[blob_id] = blob # remove blob if it has reached the limit for tracking failures if blob.num_consecutive_tracking_failures >= self.mctf: del self.blobs[blob_id] if self.frame_count >= self.detection_interval: # rerun detection droi_frame = get_roi_frame(self.frame, self.droi) _bounding_boxes, _classes, _confidences = get_bounding_boxes( droi_frame, self.detector) self.blobs = add_new_blobs(_bounding_boxes, _classes, _confidences, self.blobs, self.frame, self.tracker, self.mcdf) self.blobs = remove_duplicates(self.blobs) self.frame_count = 0 self.frame_count += 1
def count(self, frame): self.frame = frame counts_dict = {} blobs_list = list(self.blobs.items()) blobs_list = Parallel(n_jobs=num_cores, prefer='threads')( delayed(update_blob_tracker)(blob, blob_id, self.frame) for blob_id, blob in blobs_list) self.blobs = dict(blobs_list) for blob_id, blob in blobs_list: blob, self.counts = attempt_count(blob, blob_id, self.counting_lines, self.counts) self.blobs[blob_id] = blob if blob.num_consecutive_tracking_failures >= self.mctf: del self.blobs[blob_id] if self.frame_count >= self.di: droi_frame = get_roi_frame(self.frame, self.droi) _bounding_boxes, _classes, _confidences = get_bounding_boxes( droi_frame) self.blobs = add_new_blobs(_bounding_boxes, _classes, _confidences, self.blobs, self.frame, self.tracker, self.mcdf) self.blobs = remove_duplicates(self.blobs) self.frame_count = 0 self.frame_count += 1
def count(self, frame, dict1, frames_count, fps): self.frame = frame seconds = frames_count / fps video_time = str(datetime.timedelta(seconds=seconds)) blobs_list = list(self.blobs.items()) # update blob trackers blobs_list = Parallel(n_jobs=NUM_CORES, prefer='threads')( delayed(update_blob_tracker)(blob, blob_id, self.frame) for blob_id, blob in blobs_list) self.blobs = dict(blobs_list) for blob_id, blob in blobs_list: if (dict1.get(blob_id) is None): print('No value Present for Object Id : ' + blob_id) dict1[blob_id] = blob.type_confidence print('Updated Map') print("duration in seconds:", seconds) print("video time:", video_time) else: confidencePercentage = dict1.get(blob_id) if (blob.type_confidence > confidencePercentage): dict1.update({blob_id: blob.type_confidence}) print('Confidence updated for Object' + blob_id + 'with value ' + str(blob.type_confidence)) # count object if it has crossed a counting line blob, self.counts = attempt_count(blob, blob_id, self.counting_lines, self.counts) self.blobs[blob_id] = blob # remove blob if it has reached the limit for tracking failures if blob.num_consecutive_tracking_failures >= self.mctf: del self.blobs[blob_id] if self.frame_count >= self.detection_interval: # rerun detection droi_frame = get_roi_frame(self.frame, self.droi) _bounding_boxes, _classes, _confidences = get_bounding_boxes( droi_frame, self.detector) self.blobs = add_new_blobs(_bounding_boxes, _classes, _confidences, self.blobs, self.frame, self.tracker, self.mcdf) self.blobs = remove_duplicates(self.blobs) self.frame_count = 0 self.frame_count += 1
def count(self, frame): self.frame = frame blobs_list = list(self.blobs.items()) time0 = time.time() # update blob trackers blobs_list = [ update_blob_tracker(blob, blob_id, self.frame) for blob_id, blob in blobs_list ] # blobs_list = Parallel(n_jobs=num_cores, prefer='threads')( # delayed(update_blob_tracker)(blob, blob_id, self.frame) for blob_id, blob in blobs_list # ) tracking_time_ms = (time.time() - time0) * 1000 print("%d - %.3f" % (len(blobs_list), tracking_time_ms)) self.running_average(tracking_time_ms, is_detection=False) self.blobs = dict(blobs_list) for blob_id, blob in blobs_list: # count vehicle if it has crossed a counting line blob, self.counts = attempt_count(blob, blob_id, self.counting_lines, self.counts) self.blobs[blob_id] = blob # remove blob if it has reached the limit for tracking failures if blob.num_consecutive_tracking_failures >= self.mctf: del self.blobs[blob_id] if self.frame_count >= self.di: time0 = time.time() # rerun detection if self.use_droi: droi_frame = get_roi_frame(self.frame, self.droi) else: droi_frame = self.frame _bounding_boxes, _classes, _confidences = get_bounding_boxes( droi_frame, self.detector) self.blobs = add_new_blobs(_bounding_boxes, _classes, _confidences, self.blobs, self.frame, self.tracker, self.mcdf) self.blobs = remove_duplicates(self.blobs) self.frame_count = 0 det_time = float(time.time() - time0) * 1000 print("\t", det_time) self.running_average(det_time, is_detection=True) self.frame_count += 1
def count_queue(self, frame): self.frame = frame for blob_id, blob in self.blobs.items(): self.in_queue.put((blob, blob_id, self.frame)) num_blobs = len(self.blobs) processed_blobs = 0 while processed_blobs < num_blobs: blob_id, blob = self.out_queue.get(True) blob, self.counts = attempt_count(blob, blob_id, self.counting_lines, self.counts) self.blobs[blob_id] = blob # remove blob if it has reached the limit for tracking failures if blob.num_consecutive_tracking_failures >= self.mctf: del self.blobs[blob_id] processed_blobs += 1 if self.frame_count >= self.di: # rerun detection if self.use_droi: droi_frame = get_roi_frame(self.frame, self.droi) else: droi_frame = self.frame _bounding_boxes, _classes, _confidences = get_bounding_boxes( droi_frame, self.detector) self.blobs = add_new_blobs(_bounding_boxes, _classes, _confidences, self.blobs, self.frame, self.tracker, self.mcdf) self.blobs = remove_duplicates(self.blobs) self.frame_count = 0 self.frame_count += 1
def count(self, frame,frames_processed, processing_frame_rate): self.frame = frame self.processing_frame_rate = processing_frame_rate self.frames_processed = frames_processed self.isWaiting = 0 # rescan_requested = False # self.nearestBlobLastFrameDistance = self.nearestBlobDistance blobs_list = list(self.blobs.items()) # update blob trackers blobs_list = Parallel(n_jobs=NUM_CORES, prefer='threads')( delayed(update_blob_tracker)(blob, blob_id, self.frame) for blob_id, blob in blobs_list ) self.blobs = dict(blobs_list) for blob_id, blob in blobs_list: # count vehicle if it has crossed a counting line blob, self.counts = attempt_count(blob, blob_id, self.counting_lines,self.speed_estimation_lines , self.counts, self.frames_processed,self.processing_frame_rate) self.blobs[blob_id] = blob # remove blob if it has reached the limit for tracking failures if blob.num_consecutive_tracking_failures >= self.mctf: del self.blobs[blob_id] if self.detector == 'yolo': blob.onRoad = str(_is_on_which_roads(self.roads, blob)) blob.distance = distance_cal(blob.position,self.camera_height,self.focal_length,self.pixel_length,self.resolution,self.vanishing_point) # self.NearestBlob, self.nearestBlobPosition , rescan_requested = UpdateNearestBlobPosition(blob, blob_id, blobs_list, self.nearestBlobPosition, self.NearestBlob, rescan_requested) # self.nearestBlobDistance = distance_cal(self.nearestBlobPosition[1]) # check blob is waiting if self.detector == 'yolo_p': if self.veh_light == 0: point = Point(blob.bottom_point) polygon = Polygon(self.waiting_zone[0:4]) polygon2 = Polygon(self.waiting_zone[-4:]) if polygon.contains(point) == True or polygon2.contains(point) == True: blob.isJaywalker = False self.isWaiting += 1 else: blob.isJaywalker = True self.jaywalker_flag = True if self.ped_light != 0: blob.isJaywalker = False self.jaywalker_flag = False # ============================================================================= # if rescan_requested: # self.nearestBlob1FrameDistance=[] # self.nearestBlobPosition = (0,0) # for blob_id, blob in blobs_list: # self.NearestBlob, self.nearestBlobPosition , rescan_requested = UpdateNearestBlobPosition(blob, blob_id, blobs_list, self.nearestBlobPosition, self.NearestBlob,rescan_requested) # self.nearestBlobDistance = distance_cal(self.nearestBlobPosition[1]) # self.nearestBlobLastFrameDistance = self.nearestBlobDistance # rescan_requested = False # ============================================================================= # if self.processing_frame_rate > 0 and self.nearestBlobPosition[1] > 0 and self.nearestBlobDistance != self.nearestBlobLastFrameDistance and rescan_requested == False: # ============================================================================= # print('nor_list'+str(normalizing_1frame_distance(self.nearestBlobDistance,self.nearestBlobLastFrameDistance,self.nearestBlob1FrameDistance))) # print('list'+str(self.nearestBlob1FrameDistance)) # print('1 '+str(self.nearestBlobDistance)) # print('2 '+str(self.nearestBlobLastFrameDistance)) # ============================================================================= # self.NearestBlob_remaining_time = cal_remaining_time( (self.nearestBlobDistance / normalizing_1frame_distance(self.nearestBlobDistance,self.nearestBlobLastFrameDistance,self.nearestBlob1FrameDistance)),1,self.processing_frame_rate) if self.frame_count >= self.detection_interval: # rerun detection droi_frame = get_roi_frame(self.frame, self.droi) _bounding_boxes, _classes, _confidences = get_bounding_boxes(droi_frame, self.detector) self.blobID += 1 self.blobs = add_new_blobs(_bounding_boxes, _classes, _confidences, self.blobs, self.frame, self.tracker, self.mcdf, self.blobID) self.blobs = remove_duplicates(self.blobs) self.frame_count = 0 self.frame_count += 1