예제 #1
0
    def __init__(self, cfg, args, video_path, fcos=None):
        self.cfg = cfg
        self.args = args
        self.video_path = video_path
        self.logger = get_logger("root")

        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            warnings.warn("Running in cpu mode which maybe very slow!",
                          UserWarning)

        if args.display:
            cv2.namedWindow("test", cv2.WINDOW_NORMAL)
            cv2.resizeWindow("test", args.display_width, args.display_height)

        if args.cam != -1:
            print("Using webcam " + str(args.cam))
            self.vdo = cv2.VideoCapture(args.cam)
        else:
            self.vdo = cv2.VideoCapture()
        if fcos is not None:
            self.detector = fcos
        else:
            fcos = FCOSEvaluator(
                "weights/FCOS_imprv_R_50_FPN_1x.pth",
                config="./configs/fcos/fcos_imprv_R_50_FPN_1x.yaml")
            #print("fcos.config",fcos.config)
            fcos.prepare_detector()  #build_detector(cfg, use_cuda=use_cuda)
            self.detector = fcos
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
    def __init__(self, cfg, args):
        # Create a VideoCapture object
        self.cfg = cfg
        self.args = args
        use_cuda = self.args.use_cuda and torch.cuda.is_available()

        if not use_cuda:
            raise UserWarning("Running in cpu mode!")

        self.detector = build_detector(cfg, use_cuda=use_cuda)
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
        self.class_names = self.detector.class_names

        self.vdo = cv2.VideoCapture(self.args.input)
        self.status, self.frame = None, None
        self.total_frames = int(
            cv2.VideoCapture.get(self.vdo, cv2.CAP_PROP_FRAME_COUNT))
        self.im_width = int(self.vdo.get(cv2.CAP_PROP_FRAME_WIDTH))
        self.im_height = int(self.vdo.get(cv2.CAP_PROP_FRAME_HEIGHT))

        self.output_frame = None

        self.thread = ThreadPoolExecutor(max_workers=1)
        self.thread.submit(self.update)
        print('streaming started ...')
예제 #3
0
    def __init__(self, cfg, args, video_path):
        self.cfg = cfg
        self.args = args
        self.video_path = video_path
        self.logger = get_logger("root")

        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            warnings.warn("Running in cpu mode which maybe very slow!",
                          UserWarning)

        if args.display:
            cv2.namedWindow("test", cv2.WINDOW_NORMAL)
            cv2.resizeWindow("test", args.display_width, args.display_height)

        if args.cam != -1:
            print("Using webcam " + str(args.cam))
            self.vdo = cv2.VideoCapture(args.cam)
        else:
            # 把一个ViedeoCapture 类 赋值给vdo 实例
            # 这个实例 包含 open method 可以
            self.vdo = cv2.VideoCapture()

        # 返回 yolov3 和 deepsort 的实例对象
        self.detector = build_detector(cfg, use_cuda=use_cuda)
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
        self.class_names = self.detector.class_names  # ????
    def __init__(self, width, height, classes, safezone, camera_fov_x,
                 target_height_m):
        # Set internal variables.
        self.width = width
        self.height = height
        self.classes = classes
        self.safezone = safezone
        self.camera_fov_x = camera_fov_x
        self.target_height_m = target_height_m

        self.cfg = get_merged_config()
        use_cuda = torch.cuda.is_available()
        if not use_cuda:
            raise UserWarning("Running in cpu mode!")

        self.cam2world = Cam2World(self.width, self.height, self.camera_fov_x)
        self.cls_dict = {0: 'person', 2: 'car', 7: 'car'}

        self.detector = build_detector(self.cfg, use_cuda=use_cuda)
        self.deepsort = build_tracker(self.cfg,
                                      cam2world=self.cam2world,
                                      obj_height_meters=self.target_height_m,
                                      use_cuda=use_cuda)
        self.class_names = self.detector.class_names
        self.bbox_xyxy = []
        self.identities = []
        self.target_id = []

        # configuring logger:
        self.logger = DeepSortLogger()
        self.frame = -1
예제 #5
0
    def __init__(self, cfg, args, video_path):
        self.cfg = cfg
        self.args = args
        self.video_path = video_path
        self.logger = get_logger("root")

        # delete all files
        # for f in glob.glob("./data/*"):
        #     os.remove(f)

        self.status_dict = {0: "OK", 1: "ACQUIRED", 2: "VIOLATION"}

        self.telegram_bot = telegram()

        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            warnings.warn("Running in cpu mode which maybe very slow!",
                          UserWarning)

        if args.display:
            cv2.namedWindow("test", cv2.WINDOW_NORMAL)
            cv2.resizeWindow("test", args.display_width, args.display_height)

        if args.cam != -1:
            print("Using webcam " + str(args.cam))
            # self.vdo = cv2.VideoCapture(args.cam)
            self.vdo = cv2.VideoCapture(args.cam)
        else:
            self.vdo = cv2.VideoCapture()
        self.detector = build_detector(cfg, use_cuda=use_cuda)
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
        self.class_names = self.detector.class_names
        self.H = get_homography()
예제 #6
0
    def __init__(self, cfg, args, video_path, video_bar, vt_box_dict):
        self.cfg = cfg
        self.args = args
        self.video_path = video_path
        self.video_name = os.path.splitext(os.path.split(video_path)[1])[0]
        self.logger = get_logger("root")
        self.video_bar = video_bar
        self.vt_box_dict = vt_box_dict
        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            warnings.warn("Running in cpu mode which maybe very slow!",
                          UserWarning)

        if args.display:
            cv2.namedWindow("test", cv2.WINDOW_NORMAL)
            cv2.resizeWindow("test", args.display_width, args.display_height)

        if args.cam != -1:
            print("Using webcam " + str(args.cam))
            self.vdo = cv2.VideoCapture(args.cam)
        else:
            self.vdo = cv2.VideoCapture()

        self.detector = build_detector(cfg, use_cuda=use_cuda)
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
        self.class_names = self.detector.class_names
예제 #7
0
    def __init__(self, cfg, args, video_path):

        rospy.init_node('coordinate_publisher')
        rospy.loginfo('Video stream has started')

        self.cfg = cfg
        self.args = args
        self.video_path = video_path
        self.logger = get_logger("root")

        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            warnings.warn("Running in cpu mode which maybe very slow!",
                          UserWarning)

        if args.display:
            cv2.namedWindow("test", cv2.WINDOW_NORMAL)
            cv2.resizeWindow("test", args.display_width, args.display_height)

        if args.cam != -1:
            print("Using webcam " + str(args.cam))
            self.vdo = cv2.VideoCapture(args.cam)
        else:
            self.vdo = cv2.VideoCapture()
        self.detector = build_detector(cfg, use_cuda=use_cuda)
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
        self.class_names = self.detector.class_names
예제 #8
0
    def __init__(self, cfg, args):
        self.cfg = cfg
        self.args = args
        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            warnings.warn("Running in cpu mode which maybe very slow!",
                          UserWarning)

        if args.display:
            cv2.namedWindow("test", cv2.WINDOW_NORMAL)
            cv2.resizeWindow("test", args.display_width, args.display_height)

        if args.cam != -1:
            print("Using webcam " + str(args.cam))
            self.vdo = cv2.VideoCapture(args.cam)
        else:
            self.vdo = cv2.VideoCapture()
        class_names = [
            name.strip() for name in open(args.label_file).readlines()
        ]
        net = create_mobilenetv2_ssd_lite(len(class_names), is_test=True)
        net.load(args.detector_model)
        self.detector = create_mobilenetv2_ssd_lite_predictor(net)
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
        self.class_names = class_names
    def __init__(self, cfg, args, video_path):
        self.cfg = cfg
        self.args = args
        self.video_path = video_path
        self.logger = get_logger("root")
        self.logger.info(f"Video rate is {self.video_path}")

        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            warnings.warn("Running in cpu mode which maybe very slow!",
                          UserWarning)

        if args.display:
            cv2.namedWindow("test", cv2.WINDOW_NORMAL)
            cv2.resizeWindow("test", args.display_width, args.display_height)

        if args.cam != -1:
            print("Using webcam " + str(args.cam))
            self.vdo = cv2.VideoCapture(args.cam)
        else:
            self.vdo = cv2.VideoCapture()

        # Uniformly sample frames to save resources
        # Copy the previous result when a frame is skipped
        self.logger.info(f"Sample rate is {args.sample_rate}")
        self.skip_frame = int(1 / args.sample_rate)

        self.logger.info(f"Detection model is set to {args.detection_model}")
        self.detector = build_detector(args.detection_model,
                                       cfg,
                                       use_cuda=use_cuda)
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
        self.class_names = self.detector.class_names
        self.temp_tesult = []
예제 #10
0
    def __init__(self, cfg, args, image_path, save_filename, im_width,
                 im_height):
        self.cfg = cfg
        self.args = args
        self.image_path = image_path

        self.logger = get_logger("root")
        self.save_filename = save_filename
        self.im_width = im_width
        self.im_height = im_height

        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            warnings.warn("Running in cpu mode which maybe very slow!",
                          UserWarning)

        # if args.display:
        #     cv2.namedWindow("test", cv2.WINDOW_NORMAL)
        #     cv2.resizeWindow("test", args.display_width, args.display_height)

#         if args.cam != -1:
#             print("Using webcam " + str(args.cam))
#             self.vdo = cv2.VideoCapture(args.cam)
#         else:
#             self.vdo = cv2.VideoCapture()
        self.detector = detect(is_xywh=True, use_cuda=True)
        #print(self.detector)
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
    def __init__(self, cfg):
        use_cuda = torch.cuda.is_available()
        if not use_cuda:
            raise UserWarning("Running in cpu mode!")

        self.detector = build_detector(cfg, use_cuda=True)
        self.deepsort = build_tracker(cfg, use_cuda=True)
        self.class_names = self.detector.class_names
예제 #12
0
    def __init__(self, cfg):
        self.cfg = cfg

        self.cap = cv2.VideoCapture(0)
        #self.cap = cv2.VideoCapture(0)
        self.detector = build_detector(cfg, use_cuda=cpu)
        self.deepsort = build_tracker(cfg, use_cuda=cpu)
        self.class_names = self.detector.class_names
예제 #13
0
 def initialize_deep_sort(self):
     # initialize deep sort object
     cfg = get_config()
     cfg.merge_from_file(self.deep_sort_path)
     use_cuda = torch.cuda.is_available()
     if not use_cuda:
         print("Running in cpu mode which maybe very slow!", UserWarning)
     return build_tracker(cfg, use_cuda=use_cuda)
예제 #14
0
파일: detect.py 프로젝트: j2eejb8/trafficAI
    def __init__(self, cfg):
        warnings.filterwarnings("ignore")
        self.cfg = cfg
        #self.args = args
        self.yolo = 0
        self.video_path = 0
        self.outputDir = 0
        self.carLocation1 = {}
        self.carLocation2 = {}
        self.carSpeed = {}
        self.carDirection = {}
        self.carPre = {}
        self.virtureLine = [[0, 0], [0, 0]]
        self.carInCnt = 0
        self.carOutCnt = 0
        self.inCar = set()
        self.outCar = set()
        self.trafficLine = []
        self.idx_frame = 0
        self.carSpeedLimit = 0
        self.filename = 0
        self.trafficJamLimit = 0
        self.rett = False
        self.carLicense = {}
        self.speed = [0, 0, 0, 0, 0, 0, 0, 0]
        self.licence = Licence()
        self.detectCar = detectCar()
        self.frameAll = 0
        self.vout = cv2.VideoWriter()
        self.carLabel = {}
        self.saveVideoFlag = True
        self.displayFlag = True
        self.videoFps = 0
        self.videoHeight = 0
        self.trafficLine1 = []
        self.trafficLine2 = []
        self.carInfor = {}
        self.videoWidth = 0
        self.carSpeedLimit = 0
        self.trafficJamLimit = 0
        self.yolov5weight = 0
        self.carFromLeft = {}
        self.carFromRight = {}
        self.carFromForward = {}
        self.carTurn = {}
        self.endFlag = False
        self.illegal = {}
        self.trafficLightFlag = False
        self.dir = ['UP', 'RIGHT', 'DOWN', "LEFT"]
        #self.idx_frame
        use_cuda = torch.cuda.is_available()
        if not use_cuda:
            warnings.warn("Running in cpu mode which maybe very slow!",
                          UserWarning)

        self.detector = self.yolo
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
    def __init__(self, cfg, args, path):
        self.logger = get_logger("root")
        self.args = args
        self.video_path = path
        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            warnings.warn("Running in cpu mode which maybe very slow!", UserWarning)

        self.person_detect = Person_detect(self.args, self.video_path)
        imgsz = check_img_size(args.img_size, s=32)  # self.model.stride.max())  # check img_size
        self.dataset = LoadImages(self.video_path, img_size=imgsz)
        self.deepsort = build_tracker(cfg, args.sort, use_cuda=use_cuda)
예제 #16
0
    def __init__(self,
                 cfg,
                 input_queue=None,
                 output_queue_vis=None,
                 output_queue_action_pred=None,
                 use_gpu=True,
                 show_video=False):
        """
        :param cfg: the prototype config
        :param input_queue: inut
        :param: output_queue: output
        :param use_gpu: (boolean) whether gpu should be use for inference
        """

        setup_environment()
        # Setup logging format
        logging.setup_logging(cfg.OUTPUT_DIR)

        self.cfg = cfg
        self.show_video = show_video

        # The queues from the main thread used for multiprocessing
        self.output_detection_queue = input_queue
        if self.show_video:
            self.output_tracker_queue_visualization = output_queue_vis
        self.output_tracker_queue_action_recognition = output_queue_action_pred

        # Used to order images retrieved from the two queues used as  input
        self.get_idx = -1

        # Has the previous process terminated?
        self.first_poison_pill_received = False
        # True if self.first_poison_pill_received and get does not lead to any results and self.result_rank is empty
        self.output_detection_queue_is_finished = False

        # Whether we will use a gpu or not
        use_gpu = use_gpu and torch.cuda.is_available()

        # The tracker we will use for object detection
        self.deepsort = build_tracker(cfg, use_cuda=use_gpu)

        # A list that contains and is sorted by get_idxs (ascending) -> result_rank[0] is smallest get_idx
        self.result_rank = []
        # A list that contains the images (ndarray) image with shape (H, W, C) (in BGR order) and [0,255])
        self.result_img_data = []
        # A list that contains the prediction results (predictions {dict}) and that is
        # also sorted by the get_idxs -> corresponding to result_rank
        self.result_prediction_data = []

        # The process for person detection
        self.update_tracker_with_next_image_prcocess = mp.Process(
            target=self.update_tracker_with_next_image, args=())
예제 #17
0
    def __init__(self, cfg, args, video_path, result_filename="results"):
        self.cfg = cfg
        self.args = args
        self.result_filename = result_filename
        self.video_path = video_path
        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            warnings.warn("Running in cpu mode which maybe very slow!",
                          UserWarning)

        self.vdo = cv2.VideoCapture()
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
        self.class_names = args.class_names
예제 #18
0
    def __init__(self, cfg, args, name):
        self.cfg = cfg
        self.args = args
        self.name = name
        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            raise UserWarning("Running in cpu mode!")

        self.indir = "/mnt/Disk1/qingl/data/MOT16/train/" + self.name + "/img1/"
        self.outdir = dir = "/home/qingl/antonio/mot16/baseline/" + self.name + ".txt"
        f = open(self.outdir, 'w')
        f.truncate()
        self.detector = build_detector(cfg, use_cuda=use_cuda)
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
        self.class_names = self.detector.class_names
    def __init__(self, cfg, args):
        self.cfg = cfg
        self.args = args
        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            raise UserWarning("Running in cpu mode!")

        if args.display:
            cv2.namedWindow("test", cv2.WINDOW_NORMAL)
            cv2.resizeWindow("test", args.display_width, args.display_height)

        self.vdo = cv2.VideoCapture()
        self.detector = build_detector(cfg, use_cuda=use_cuda)
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
        self.class_names = self.detector.class_names
예제 #20
0
    def __init__(self, cfg, engine_file_path):
        self.cfg = cfg
        # self.args = args

        self.deepsort = build_tracker(cfg, use_cuda=True)
        #---tensorrt----#
        self.engine = get_engine(engine_file_path)
        self.context = self.engine.create_execution_context()
        self.inputs, self.outputs, self.bindings, self.stream = common.allocate_buffers(
            self.engine)
        # ---tensorrt----#

        #---input info for yolov3-416------#
        self.input_resolution_yolov3_HW = (416, 416)

        self.preprocessor = PreprocessYOLO(self.input_resolution_yolov3_HW)

        # self.image_raw, self.image = self.preprocessor.process(ori_im)

        # self.shape_orig_WH = image_raw.size

        self.output_shapes = [(1, 255, 13, 13), (1, 255, 26, 26),
                              (1, 255, 52, 52)]
        self.postprocessor_args = {
            "yolo_masks": [(6, 7, 8), (3, 4, 5), (0, 1, 2)],
            # A list of 3 three-dimensional tuples for the YOLO masks
            "yolo_anchors": [
                (10, 13),
                (16, 30),
                (33, 23),
                (30, 61),
                (62, 45),
                # A list of 9 two-dimensional tuples for the YOLO anchors
                (59, 119),
                (116, 90),
                (156, 198),
                (373, 326)
            ],
            "obj_threshold":
            0.6,  # Threshold for object coverage, float value between 0 and 1
            "nms_threshold":
            0.5,
            # Threshold for non-max suppression algorithm, float value between 0 and 1
            "yolo_input_resolution":
            self.input_resolution_yolov3_HW
        }

        self.postprocessor = PostprocessYOLO(**self.postprocessor_args)
    def __init__(self, cfg, args):
        self.cfg = cfg
        self.args = args
        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            warnings.warn("Running in cpu mode which maybe very slow!",
                          UserWarning)

        if args.display:
            cv2.namedWindow("test", cv2.WINDOW_NORMAL)
            cv2.resizeWindow("test", args.display_width, args.display_height)

        if args.cam != -1:
            print("Using webcam " + str(args.cam))
            self.vdo = cv2.VideoCapture(args.cam)
        else:
            self.vdo = cv2.VideoCapture()
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
예제 #22
0
    def __init__(self, cfg, args):
        self.cfg = cfg
        self.args = args
        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            print("Running on CPU!")
        else:
            print("Running on CUDA!")

        if args.display:
            cv2.namedWindow("test", cv2.WINDOW_NORMAL)
            cv2.resizeWindow("test", args.display_width, args.display_height)

        self.vdo = cv2.VideoCapture()
        self.detector = build_detector(cfg, use_cuda=use_cuda)
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
        self.class_names = self.detector.class_names
        rospy.init_node('workspace_monitoring_node')
예제 #23
0
    def __init__(self, args):
        print('Initialize DeepSORT & YOLO-V5')
        # ***************** Initialize ******************************************************
        self.args = args

        self.img_size = args.img_size  # image size in detector, default is 640
        self.frame_interval = args.frame_interval  # frequency

        self.device = select_device(args.device)
        self.half = self.device.type != 'cpu'  # half precision only supported on CUDA

        # create video capture ****************
        if args.display:
            cv2.namedWindow("test", cv2.WINDOW_NORMAL)
            cv2.resizeWindow("test", args.display_width, args.display_height)

        if args.cam != -1:
            print("Using webcam " + str(args.cam))
            self.vdo = cv2.VideoCapture(args.cam)
        else:
            self.vdo = cv2.VideoCapture()

        # ***************************** initialize DeepSORT **********************************
        cfg = get_config()
        cfg.merge_from_file(args.config_deepsort)

        use_cuda = self.device.type != 'cpu' and torch.cuda.is_available()
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)

        # ***************************** initialize YOLO-V5 **********************************
        self.detector = torch.load(
            args.weights,
            map_location=self.device)['model'].float()  # load to FP32
        self.detector.to(self.device).eval()
        if self.half:
            self.detector.half()  # to FP16

        self.names = self.detector.module.names if hasattr(
            self.detector, 'module') else self.detector.names

        print('Done..')
        if self.device == 'cpu':
            warnings.warn("Running in cpu mode which maybe very slow!",
                          UserWarning)
예제 #24
0
    def __init__(self, cfg, args, video_path=None, redis=None):
        self.cfg = cfg
        self.args = args
        self.video_path = video_path
        self.redis = redis
        self.cur_objects = {}
        self.reset_interval = 0
        # self.logger = get_logger("root")
        self.is_close = False
        self.int2command = {1: "open", 2: "close"}
        self.start = time.time()
        # 七牛云图床上传权限申请
        self.q = Auth(self.cfg.sys.qiniu.access_key,
                      self.cfg.sys.qiniu.secret_key)

        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            warnings.warn("Running in cpu mode which maybe very slow!",
                          UserWarning)

        if args.display:
            cv2.namedWindow("test", cv2.WINDOW_NORMAL)
            cv2.resizeWindow("test", args.display_width, args.display_height)

        if args.cam != -1:
            print("Using webcam " + str(args.cam))
            self.vdo = RTSCapture.create(args.cam,
                                         self.cfg.sys.restart_interval)
            self.vdo.start_read()
        else:
            self.vdo = cv2.VideoCapture()
        # self.detector = build_detector(cfg, use_cuda=use_cuda)
        # 构建目标检测器
        self.detector = torch.hub.load('ultralytics/yolov5',
                                       'yolov5s',
                                       pretrained=True,
                                       force_reload=False)
        self.detector.conf = 0.6
        classes = list(self.cfg.classes.keys())[:-2]
        self.detector.classes = list(map(lambda x: int(x), classes))
        if use_cuda:
            self.detector.cuda()
        # 构建目标跟踪器
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
예제 #25
0
    def __init__(self, cfg, args):
        self.cfg = cfg
        self.args = args
        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            warnings.warn("请使用gpu测试!", UserWarning)

        # opencv输出界面设置
        if args.display:
            cv2.namedWindow("test", cv2.WINDOW_NORMAL)
            cv2.resizeWindow("test", args.display_width, args.display_height)

        # 是否使用摄像头进行测试
        if args.cam != -1:
            print("使用摄像头 " + str(args.cam))
            self.vdo = cv2.VideoCapture(0, cv2.CAP_DSHOW)
        else:
            self.vdo = cv2.VideoCapture()
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
예제 #26
0
    def __init__(self, cfg, args):
        self.cfg = cfg
        self.args = args
        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            warnings.warn("Running in cpu mode!")

        self.vdo = cv2.VideoCapture()
        self.detector = build_detector(cfg, use_cuda=use_cuda)
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
        self.class_names = self.detector.class_names

        # Configure output video and json
        self.logger = BboxToJsonLogger()
        filename, extension = splitext(basename(self.args.VIDEO_PATH))
        self.output_file = join(self.args.save_path, f'{filename}.avi')
        self.json_output = join(self.args.save_path, f'{filename}.json')
        if not isdir(dirname(self.json_output)):
            makedirs(dirname(self.json_output))
예제 #27
0
    def __init__(self, cfg, args, images_path):
        self.cfg = cfg
        self.args = args
        self.images_path = images_path
        self.logger = get_logger("root")

        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            warnings.warn("Running in cpu mode which maybe very slow!",
                          UserWarning)

        if args.display:
            cv2.namedWindow("test", cv2.WINDOW_NORMAL)
            cv2.resizeWindow("test", args.display_width, args.display_height)

        assert os.path.isdir(self.images_path), "Path error"
        self.imgs_filenames = sorted(
            os.listdir(os.path.join(self.images_path, 'img1')))
        self.detector = build_detector(cfg, use_cuda=use_cuda)
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
        self.class_names = self.detector.class_names
    def __init__(self, cfg, args, video_path, Flag, result_filename="results"):
        self.cfg = cfg
        self.args = args
        self.result_filename = result_filename
        self.video_path = video_path
        self.Flag = Flag #Flag = True save features
        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            warnings.warn("Running in cpu mode which maybe very slow!", UserWarning)

        if args.display:
            cv2.namedWindow("test", cv2.WINDOW_NORMAL)
            cv2.resizeWindow("test", args.display_width, args.display_height)

        if args.cam != -1:
            print("Using webcam " + str(args.cam))
            self.vdo = cv2.VideoCapture(args.cam)
        else:
            self.vdo = cv2.VideoCapture()
        self.detector = build_detector(cfg, use_cuda=use_cuda)
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
        self.class_names = self.detector.class_names
예제 #29
0
    def __init__(self):
        cfg = get_config()
        cfg.merge_from_file(opt.deep_sort_path)
        use_cuda = torch.cuda.is_available()
        if not use_cuda:
            print("Using CPU")

        desired_classes = [
            'person', 'bicycle', 'car', 'motorbike', 'bus', 'truck'
        ]
        class_names, desired_class_names = read_class_names(
            opt.label_names_path, desired_classes=desired_classes)
        self.class_names = class_names

        self.yolo = Load_Yolo_Model(track_only=desired_class_names,
                                    conf_thres=opt.confidence,
                                    weights=opt.yolo_path)
        self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
        self.log = logging.getLogger()
        self.log.setLevel(logging.INFO)
        self.log.addHandler(TqdmLoggingHandler())
        print("Initialized!")
예제 #30
0
    def __init__(self, args, video_path):
        self.args = args
        self.video_path = video_path
        self.logger = get_logger("root")

        use_cuda = args.use_cuda and torch.cuda.is_available()
        if not use_cuda:
            warnings.warn("Running in cpu mode which maybe very slow!",
                          UserWarning)

        if args.display:
            cv2.namedWindow("test", cv2.WINDOW_NORMAL)
            cv2.resizeWindow("test", args.display_width, args.display_height)

        if args.cam != -1:
            print("Using webcam " + str(args.cam))
            self.vdo = cv2.VideoCapture(args.cam)
        else:
            self.vdo = cv2.VideoCapture()
        self.detector = build_detector()
        self.deepsort = build_tracker(use_cuda=True)
        self.class_names = self.detector.class_names