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 ...')
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()
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 = []
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
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
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
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, 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 = build_detector(cfg, use_cuda=use_cuda, detector_name='Rcnn') #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
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
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
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, 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) 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.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: 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')
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))
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.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, config, arguments, video_path=None): self.cfg = config self.args = arguments self.video_fps = 60 # 默认输出视频FPS为60 if video_path is not None: self.args.video_path = video_path is_use_cuda = self.args.use_cuda and torch.cuda.is_available() if not is_use_cuda: print("Running programme in cpu") else: print("Running programme in gpu") if self.args.display: # 创建可视化窗口 cv2.namedWindow("test", cv2.WINDOW_NORMAL) cv2.resizeWindow("test", args.show_width, args.show_height) self.vdo = cv2.VideoCapture() self.detector = build_detector(self.cfg, use_cuda=is_use_cuda) self.deepsort = build_tracker(self.cfg, use_cuda=is_use_cuda)
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): 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 args.backbone == 'retinaface': return_layers = {'layer2':1,'layer3':2,'layer4':3} from retinaface import anchors,losses,torchvision_model,utils RetinaFace = torchvision_model.create_retinaface(return_layers) retina_dict = RetinaFace.state_dict() pre_state_dict = torch.load('model.pt') pretrained_dict = {k[7:]: v for k, v in pre_state_dict.items() if k[7:] in retina_dict} RetinaFace.load_state_dict(pretrained_dict) RetinaFace = RetinaFace.cuda() RetinaFace.eval() self.detector = RetinaFace elif args.backbone == 'yolov3': self.detector = build_detector(cfg, use_cuda=use_cuda) self.class_names = self.detector.class_names self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
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: self.vdo = cv2.VideoCapture() self.detector = build_detector(cfg, use_cuda=use_cuda, detector_name='EfficientDet') self.deepsort = build_tracker(cfg, use_cuda=use_cuda)
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: self.vdo = cv2.VideoCapture() self.detector = build_detector(cfg, use_cuda=use_cuda) self.deepsort = build_tracker(cfg, use_cuda=use_cuda) self.traj_ped = individual_TF.IndividualTF(2, 3, 3, N=6, d_model=512, d_ff=2048, h=8, dropout=0.1, mean=[0, 0], std=[0, 0]).to(device) self.traj_ped.load_state_dict( torch.load(f'Trajectory/models/Individual/eth_train/00013.pth', map_location=torch.device('cpu'))) self.traj_ped.eval() self.traj_endeffector = individual_TF.IndividualTF(2, 3, 3, N=6, d_model=512, d_ff=2048, h=8, dropout=0.1, mean=[0, 0], std=[0, 0]).to(device) self.traj_endeffector.load_state_dict( torch.load(f'Trajectory/models/Individual/traj_endeffector.pth', map_location=torch.device('cpu'))) self.traj_endeffector.eval() self.traj_arm = individual_TF.IndividualTF(2, 3, 3, N=6, d_model=512, d_ff=2048, h=8, dropout=0.1, mean=[0, 0], std=[0, 0]).to(device) self.traj_arm.load_state_dict( torch.load(f'Trajectory/models/Individual/traj_arm.pth', map_location=torch.device('cpu'))) self.traj_arm.eval() self.traj_probe = individual_TF.IndividualTF(2, 3, 3, N=6, d_model=512, d_ff=2048, h=8, dropout=0.1, mean=[0, 0], std=[0, 0]).to(device) self.traj_probe.load_state_dict( torch.load(f'Trajectory/models/Individual/traj_probe.pth', map_location=torch.device('cpu'))) self.traj_probe.eval() self.class_names = self.detector.class_names self.Q = {}
def __init__(self, cfg): use_cuda = torch.cuda.is_available() self.detector = build_detector(cfg, use_cuda=False) self.deepsort = build_tracker(cfg, use_cuda=False) self.class_names = self.detector.class_names
def __init__(self, args): #get rosparams yolov3_params = rospy.get_param("/YOLOV3") deepsort_params = rospy.get_param("/DEEPSORT") self.camera_fov = rospy.get_param("person_tracker/camera_fov") self.results_path = rospy.get_param("person_tracker/video_save_path") #initialize ros node to person_tracker name rospy.init_node('person_tracker', anonymous=True) rospy.loginfo('Video stream has started') #initialize publishers self.bbox_pub = rospy.Publisher("/person_tracking/bbox_center", Point, queue_size=1) self.angle_pub = rospy.Publisher("/person_tracking/target_angle", Float32, queue_size=1) self.target_present_pub = rospy.Publisher( "/person_tracking/target_present", Bool, queue_size=1) self.target_indice_pub = rospy.Publisher( "/person_tracking/target_indice", Int32, queue_size=1) self.detections_pub = rospy.Publisher( "/person_tracking/detection_indices", Int32MultiArray, queue_size=1) self.image_pub = rospy.Publisher( "/person_tracking/deepsort_image/compressed", CompressedImage) #initialize services to interact with node self.target_clear_srv = rospy.Service("/person_tracking/clear_target", clear_target, self.clear_track) self.target_choose_srv = rospy.Service( "/person_tracking/choose_target", choose_target, self.select_target) #concatenate rosparams to yolov3_deepsort style self.cfg = {"YOLOV3": yolov3_params, "DEEPSORT": deepsort_params} self.args = args #TODO:default processing if no topic or webcam given: source is jiang_fam if args.video_path: self.video_path = args.video_path self.logger = get_logger("root") use_cuda = torch.cuda.is_available() if not use_cuda: warnings.warn("Running in cpu mode which maybe very slow!", UserWarning) self.detector = build_detector(self.cfg, use_cuda=use_cuda) self.deepsort = build_tracker(self.cfg, use_cuda=use_cuda) self.class_names = self.detector.class_names if args.display: cv2.namedWindow("test", cv2.WINDOW_NORMAL) cv2.resizeWindow("test", args.display_width, args.display_height) #subscribes to comprossed image topic if topic name is given, else provide service if service argument is given if args.img_topic: self.img_subscriber = rospy.Subscriber(args.img_topic, CompressedImage, self.ros_deepsort_callback, queue_size=1, buff_size=2**24) elif args.service: self.update_tracker_srv = rospy.Service( "/person_tracking/update_tracker", update_tracker, self.ros_deepsort_callback) #check if webcam is given if compressed image topic not given elif args.camera != -1: print("Using webcam " + str(args.camera)) self.vdo = cv2.VideoCapture(args.camera) #use video path else: self.vdo = cv2.VideoCapture() if self.args.save_results: os.makedirs(self.results_path, exist_ok=True) # path of saved video and results self.save_video_path = os.path.join(self.results_path, "results.avi") self.save_results_path = os.path.join(self.results_path, "results.txt") # create video writer fourcc = cv2.VideoWriter_fourcc(*'MJPG') self.writer = cv2.VideoWriter(self.save_video_path, fourcc, 20, (640, 480)) self.idx_frame = 0 self.idx_tracked = None self.bbox_xyxy = [] self.identities = []
def multisync(arg): cam_obj = [] count = 0 idx_frame = -1 vids = args.VIDEO_PATH detector = build_detector(cfg,use_cuda= True)
# Initiaze DL stuff # Parsing args = parse_args() cfg = get_config() cfg.merge_from_file(args.config_detection) cfg.merge_from_file(args.config_deepsort) # Setup use_cuda = args.use_cuda and torch.cuda.is_available() if not use_cuda: print ("Running on CPU!") else: print ("Running on CUDA!") detector = build_detector(cfg, use_cuda=use_cuda) deepsort = build_tracker(cfg, use_cuda=use_cuda) class_names = detector.class_names # Initialize ROS stuff rospy.init_node('workspace_monitoring_node', anonymous=True) # Data Publishers pub_left = rospy.Publisher(args.LEFT_OUTPUT_TOPIC, locations_2d, queue_size=1) pub_right = rospy.Publisher(args.RIGHT_OUTPUT_TOPIC, locations_2d, queue_size=1) # Image Publisher # left_img_pub = rospy.Publisher("/left/image_raw/compressed", CompressedImage, queue_size=1) # right_img_pub = rospy.Publisher("/right/image_raw/compressed", CompressedImage, queue_size=1) # Subscribers