Esempio n. 1
0
def video_spatial_summary(df,
                          X,
                          N,
                          x_ref=X_REF,
                          constraints=None,
                          n_lines=5,
                          FPS=30 / 8,
                          verbose=1):
    # Filter invalid tracks
    if constraints is not None:
        if constraints == True:
            df = t.filter_merged_summary(df, verbose=verbose)
        else:
            # assuming constraints is a list of constraints names
            df = t.filter_merged_summary(df, constraints, verbose=verbose)

    # Assuming df is filtered and X is not - remove the filtered cars from X as well
    all_cars = df.cars if 'cars' in df.columns else df.index
    X = X.loc[:, [car for car in X.columns if car in all_cars]]

    # Interpolate missing frames
    # note: interpolate() enforces forward-extrapolation
    X_interp = X.interpolate(axis=0).where(X.bfill(axis=0).notnull())

    # Initialize data frame
    sdf = pd.DataFrame(index=X.index)

    # General info
    sdf['t'] = sdf.index / FPS
    # "detections" include filtered-out tracks; "tracks" include interpolated tracks in skipped frames
    sdf['n_detections'] = N
    sdf['n_tracks'] = [
        np.sum(np.logical_and(df['t0'] <= t0, t0 <= df['t0'] + df['dt']))
        for t0 in sdf.t
    ]

    # Spatial info
    for x1, x2 in zip(x_ref[:-1], x_ref[1:]):
        for l in np.arange(1, n_lines + 1):
            # number of cars in interval (x1,x2] in lane l
            cars = [
                car for car in all_cars if df.loc[car, f'lane_{x1:.0f}'] == l
            ]
            xl = X_interp[cars]
            sdf[f'n_x{x1:.0f}to{x2:.0f}_l{l:.0f}'] = np.sum(
                xl.notnull() & (x1 < xl) & (xl <= x2), axis=1)
            # average speed in interval (x1,x2] in lane l
            ids0 = (df[f't_{x1:.0f}'].notnull()) & (df[f't_{x2:.0f}'].notnull()) & \
                   (df[f'lane_{x1:.0f}'].notnull()) & (df[f'lane_{x1:.0f}'] == l)
            tmp = df[ids0]
            ids = (((tmp[f't_{x1:.0f}'] < t0) & (t0 <= tmp[f't_{x2:.0f}']))
                   for t0 in sdf.t)
            sdf[f'v_x{x1:.0f}to{x2:.0f}_l{l:.0f}'] = \
                [np.mean( [ np.sqrt(
                                    np.power( x2 - x1 , 2 ) +
                                    np.power( tmp.loc[i,f'y_{x2:.0f}'] - tmp.loc[i,f'y_{x1:.0f}'] , 2 )
                            ) / ( tmp.loc[i,f't_{x2:.0f}'] - tmp.loc[i,f't_{x1:.0f}'] ) ] )
                 if i.sum()>0 else np.nan for t0,i in zip(sdf.t,ids)]

    return sdf
Esempio n. 2
0
	def __init__(self, object_name, frame_dims):
		"""Creates the object and generates the histogram for the object to be tracked (object_name)."""
		self.object_name = object_name
		self.fWidth, self.fHeight = frame_dims
		self.full_track_window = (0,0,self.fWidth,self.fHeight)
		

		# Only direct references to the files seemed to work here
		try:
			self.object_image = cv2.imread("/home/macalester/catkin_ws/src/speedy_nav/res/images/" + object_name + ".jpg")
		except:
			print object_name + " image could not be read"
			
		self.averageColor = self.calcAverageColor()		
		
		object_hsv = cv2.cvtColor(self.object_image, cv2.COLOR_BGR2HSV)
		mask = cv2.inRange(object_hsv, np.array((0., 50., 30.)), np.array((255., 255., 255.)))
		self.hist = cv2.calcHist([object_hsv], [0], mask, [16], [0,255])
		cv2.normalize(self.hist, self.hist, 0, 255, cv2.NORM_MINMAX)			 
		
		#Contains trackers for objects already found by the searcher
		self.tracking = []
		
		#Tracker that is looking for new objects
		self.searcher = Tracker(self.full_track_window, False)
Esempio n. 3
0
 def scan(self, frame, hsv_frame, mask):
     """Updates all the of trackers for identified objects and updates the searcher which is looking for new objects."""
     bproj = cv2.calcBackProject([hsv_frame], [0], self.hist, [0, 255], 1)
     bproj &= mask
     for index, tracker in enumerate(self.tracking):
         original_bproj = bproj.copy()
         box, bproj, split = tracker.update(bproj)
         coords, dims, theta = box
         w, h = dims
         if split:
             self.splitTracker(tracker)
             del self.tracking[index]
             bproj = original_bproj
         if tracker.hasFound() and w > 0 and h > 0:
             cv2.ellipse(frame, box, self.averageColor, 2)
         else:
             del self.tracking[index]
     box, bproj, split = self.searcher.update(bproj.copy())
     if split:
         self.splitTracker(self.searcher)
         self.searcher = Tracker(self.frameDims,
                                 self.full_track_window,
                                 found=False)
     if self.searcher.hasFound(
     ):  # If searcher finds an object, start tracking that object and make a new searcher
         self.tracking.append(self.searcher)
         self.searcher = Tracker(self.frameDims,
                                 self.full_track_window,
                                 found=False)
     return frame
Esempio n. 4
0
    def __init__(self, object_name, frame_dims):
        """Creates the object and generates the histogram for the object to be tracked (object_name)."""
        self.object_name = object_name
        self.frameDims = frame_dims
        self.fWidth, self.fHeight = frame_dims
        #Full window, useful for reseting track windows
        self.full_track_window = (0, 0, self.fWidth, self.fHeight)

        fullStr = object_name + ".jpg"
        path = ".." + os.path.join(os.sep, "res", "images", fullStr)

        try:
            self.object_image = cv2.imread(path)
        except:
            print object_name + " image could not be read"

        self.averageColor = self.calcAverageColor()

        object_hsv = cv2.cvtColor(self.object_image, cv2.COLOR_BGR2HSV)
        mask = cv2.inRange(object_hsv, np.array((0., 50., 30.)),
                           np.array((255., 255., 255.)))
        self.hist = cv2.calcHist([object_hsv], [0], mask, [16], [0, 255])
        cv2.normalize(self.hist, self.hist, 0, 255, cv2.NORM_MINMAX)

        #Contains trackers for objects already found by the searcher
        self.tracking = []

        #Tracker that is looking for new objects
        self.searcher = Tracker(self.frameDims, self.full_track_window, False)
Esempio n. 5
0
 def scan(self, frame, hsv_frame, mask):
     """Updates all the of trackers for identified objects and updates the searcher which is looking for new objects."""
     bproj = cv2.calcBackProject([hsv_frame], [0], self.hist, [0,255], 1)        
     bproj &= mask        
     for index, tracker in enumerate(self.tracking):
         original_bproj = bproj.copy()
         box, bproj, split = tracker.update(bproj)
         coords, dims, theta = box
         w,h = dims
         if split:
             self.splitTracker(tracker)
             del self.tracking[index]
             bproj = original_bproj
         if tracker.hasFound() and w > 0 and h > 0:
             cv2.ellipse(frame, box, self.averageColor, 2)
         else:
             del self.tracking[index]                
     box, bproj, split = self.searcher.update(bproj.copy())        
     if split:
         self.splitTracker(self.searcher)
         self.searcher = Tracker(self.frameDims, self.full_track_window, found = False)
     if self.searcher.hasFound(): # If searcher finds an object, start tracking that object and make a new searcher
         self.tracking.append(self.searcher)
         self.searcher = Tracker(self.frameDims, self.full_track_window, found = False)            
     return frame
Esempio n. 6
0
def search_destroy(image):
    "Usa Tracking para seguir al objetivo mientras mueve la torreta y dispara"
    global p_actual
    global objetivo
    global objetivos_destruidos
    global modo
    centro_objetivo = Utiles.centro_rectangulo(objetivo)
    p_actual = Motor_Mockup.desplazamiento(p_actual, centro_objetivo)
    # Utiles.dibuja_puntos(image, [centro])
    # x1, y1, x2, y2 = aume nta_roi(objetivo)

    # cv.imshow("ROI", roi)
    # coordenadas_reducidas(image)
    # cv.waitKey(0)
    # while True:
    image, objetivos = Tracker.tracker(image)
    objetivo = Tracker.actualiza_objetivo(objetivo, objetivos)
    # image = Utiles.atencion_blur(image, objetivo)
    Utiles.dibuja_contornos(image, objetivos)
    Utiles.dibuja_rectangulo(image, objetivo, Config.UI.cyan2)
    image = Utiles.dibuja_mira(image, p_actual)
    # Comprueba si se puede disparar
    p_objetivo = Utiles.centro_rectangulo(objetivo)
    if (destruccion(p_actual, p_objetivo)):
        image = cv.putText(image, "Bang!", (p_actual[0] + 5, p_actual[1] - 5),
                           0, 1, Config.UI.rojo, 2, 16)
        # Limpia la lista de destruidos y agrega el ultimo TODO mejorar
        objetivos_destruidos.append(objetivo)
        if (len(objetivos_destruidos) > 3):
            objetivos_destruidos.pop(0)
        modo = Config.Modo.deteccion
    return image
Esempio n. 7
0
def retro_hunt_add_task():
    if request.method == 'POST':
        name = request.form.get("name", '')
        description = request.form.get("description", '')
        timeout = request.form.get("timeout", 30)
        tags = request.form.get("tags", [])
        if tags:
            tags = tags.split()
        # mails = request.form.get("mails", [])
        # if mails:
        #     mails = mails.split()

        sources = request.form.get("sources", [])
        if sources:
            sources = json.loads(sources)

        date_from = request.form.get('date_from')
        date_to = request.form.get('date_to')
        if date_from:
            date_from = date_from.replace('-', '')
        if date_to:
            date_to = date_to.replace('-', '')

        # YARA #
        yara_default_rule = request.form.get("yara_default_rule")
        yara_custom_rule = request.form.get("yara_custom_rule")
        if yara_custom_rule:
            rule = yara_custom_rule
            rule_type = 'yara_custom'
        else:
            rule = yara_default_rule
            rule_type = 'yara_default'

        user_id = current_user.get_id()

        input_dict = {
            "name": name,
            "description": description,
            "creator": user_id,
            "rule": rule,
            "type": rule_type,
            "tags": tags,
            "sources": sources,
            "timeout": timeout,  #"mails": mails,
            "date_from": date_from,
            "date_to": date_to
        }

        res = Tracker.api_create_retro_hunt_task(input_dict, user_id)
        if res[1] == 200:
            return redirect(url_for('hunters.retro_hunt_all_tasks'))
        else:
            ## TODO: use modal
            return create_json_response(res[0], res[1])
    else:
        return render_template(
            "add_retro_hunt_task.html",
            all_yara_files=Tracker.get_all_default_yara_files(),
            all_sources=item_basic.get_all_items_sources(r_list=True))
Esempio n. 8
0
def show_tracker():
    user_id = current_user.get_id()
    tracker_uuid = request.args.get('uuid', None)
    res = Term.check_term_uuid_valid_access(tracker_uuid, user_id)
    if res:  # invalid access
        return Response(json.dumps(res[0], indent=2, sort_keys=True),
                        mimetype='application/json'), res[1]

    date_from = request.args.get('date_from')
    date_to = request.args.get('date_to')

    if date_from:
        date_from = date_from.replace('-', '')
    if date_to:
        date_to = date_to.replace('-', '')

    tracker_metadata = Tracker.get_tracker_metadata(tracker_uuid,
                                                    user_id=True,
                                                    level=True,
                                                    description=True,
                                                    tags=True,
                                                    mails=True,
                                                    sources=True,
                                                    sparkline=True,
                                                    webhook=True)

    if tracker_metadata['type'] == 'yara':
        yara_rule_content = Tracker.get_yara_rule_content(
            tracker_metadata['tracker'])
    else:
        yara_rule_content = None

    if date_from:
        res = Term.parse_get_tracker_term_item(
            {
                'uuid': tracker_uuid,
                'date_from': date_from,
                'date_to': date_to
            }, user_id)
        if res[1] != 200:
            return Response(json.dumps(res[0], indent=2, sort_keys=True),
                            mimetype='application/json'), res[1]
        tracker_metadata['items'] = res[0]['items']
        tracker_metadata['date_from'] = res[0]['date_from']
        tracker_metadata['date_to'] = res[0]['date_to']
    else:
        tracker_metadata['items'] = []
        tracker_metadata['date_from'] = ''
        tracker_metadata['date_to'] = ''

    tracker_metadata['sources'] = sorted(tracker_metadata['sources'])

    return render_template("showTracker.html",
                           tracker_metadata=tracker_metadata,
                           yara_rule_content=yara_rule_content,
                           bootstrap_label=bootstrap_label)
Esempio n. 9
0
def parse_tracked_term_to_add(term, term_type, nb_words=1):
    if term_type == 'regex':
        if not is_valid_regex(term):
            return ({"status": "error", "reason": "Invalid regex"}, 400)
    elif term_type == 'word' or term_type == 'set':
        # force lowercase
        term = term.lower()
        word_set = set(term)
        set_inter = word_set.intersection(special_characters)
        if set_inter:
            return ({
                "status":
                "error",
                "reason":
                "special character not allowed",
                "message":
                "Please use a regex or remove all special characters"
            }, 400)
        words = term.split()
        # not a word
        if term_type == 'word' and len(words) > 1:
            term_type = 'set'

        # ouput format: term1,term2,term3;2
        if term_type == 'set':
            try:
                nb_words = int(nb_words)
            except:
                nb_words = 1
            if nb_words == 0:
                nb_words = 1

            words_set = set(words)
            words_set = sorted(words_set)

            if nb_words > len(words_set):
                nb_words = len(words_set)

            term = ",".join(words_set)
            term = "{};{}".format(term, nb_words)

    elif term_type == 'yara_custom':
        if not Tracker.is_valid_yara_rule(term):
            return ({
                "status": "error",
                "reason": "Invalid custom Yara Rule"
            }, 400)
    elif term_type == 'yara_default':
        if not Tracker.is_valid_default_yara_rule(term):
            return ({
                "status": "error",
                "reason": "The Yara Rule doesn't exist"
            }, 400)
    else:
        return ({"status": "error", "reason": "Incorrect type"}, 400)
    return ({"status": "success", "term": term, "type": term_type}, 200)
Esempio n. 10
0
def add_tracked_menu():
    if request.method == 'POST':
        tracker = request.form.get("tracker")
        tracker_uuid = request.form.get("tracker_uuid")
        tracker_type = request.form.get("tracker_type")
        nb_words = request.form.get("nb_word", 1)
        description = request.form.get("description", '')
        level = request.form.get("level", 0)
        tags = request.form.get("tags", [])
        mails = request.form.get("mails", [])

        # YARA #
        if tracker_type == 'yara':
            yara_default_rule = request.form.get("yara_default_rule")
            yara_custom_rule = request.form.get("yara_custom_rule")
            if yara_custom_rule:
                tracker = yara_custom_rule
                tracker_type = 'yara_custom'
            else:
                tracker = yara_default_rule
                tracker_type = 'yara_default'
        # #

        if level == 'on':
            level = 1

        if mails:
            mails = mails.split()
        if tags:
            tags = tags.split()

        input_dict = {
            "tracker": tracker,
            "type": tracker_type,
            "nb_words": nb_words,
            "tags": tags,
            "mails": mails,
            "level": level,
            "description": description
        }
        user_id = current_user.get_id()
        # edit tracker
        if tracker_uuid:
            input_dict['uuid'] = tracker_uuid
        res = Tracker.api_add_tracker(input_dict, user_id)
        if res[1] == 200:
            return redirect(url_for('hunter.tracked_menu'))
        else:
            ## TODO: use modal
            return Response(json.dumps(res[0], indent=2, sort_keys=True),
                            mimetype='application/json'), res[1]
    else:
        return render_template(
            "edit_tracker.html",
            all_yara_files=Tracker.get_all_default_yara_files())
Esempio n. 11
0
def generateLossSpace(dataPacks, scalesToTest, dt):

    lossSpace = []

    for i, scale in enumerate(scalesToTest):

        print(str(i / len(scalesToTest) * 100) + "% has been complete")

        loss = 0

        processNoiseCov = getProcessNoiseCovScale(scale)
        Tracker.ProcessNoiseCov = processNoiseCov

        for dataPack in dataPacks:

            tracker = Tracker.Tracker_SingleTarget_SingleModel_Linear_allMe()
            measurementPacks, groundTruthPacks = dataPack

            for i, (measurementPack, groundTruthPack) in enumerate(
                    zip(measurementPacks, groundTruthPacks)):

                z = tracker.feedMeasurement(
                    torch.from_numpy(measurementPack[0]), dt)
                if (z is not None):
                    loss += calculateLoss(torch.from_numpy(groundTruthPack[0]),
                                          z) / len(measurementPacks)

        loss /= len(dataPacks)

        lossSpace.append(loss)

    return lossSpace
Esempio n. 12
0
    def update(self):
        """
        Update Domain Languages
        """
        print('Fixing Tracker_uuid list ...')
        Tracker.fix_all_tracker_uuid_list()
        nb = 0
        for tracker_uuid in Tracker.get_all_tracker_uuid():
            self.r_serv.sadd('trackers_update_v3.7', tracker_uuid)
            nb += 1

        self.r_serv.set('update:nb_elem_to_convert', nb)
        self.r_serv.set('update:nb_elem_converted', 0)

        # Add background update
        self.r_serv.sadd('ail:to_update', self.version)
Esempio n. 13
0
 def start(self):
     if self.status == 'started': return
     if self.verbose > 15: print(self.name, "Staring...")
     self.started_at = time.time()
     self.downloaded_session = 0
     self.uploaded_session = 0
     self._client_factory = PeerProtocol.BTClientFactory(self)
     url = self.announce
     if not url.startswith('udp://'):
         raise (DTOCFailure("Non udp trackers not supported yet"))
     self.trackers.append(Tracker.UDPTracker(self, url, self.verbose))
     for url in self.announce_list:
         if url.startswith('udp://'):
             self.trackers.append(
                 Tracker.UDPTracker(self, url, self.verbose))
     self.lndp = LNDP.LNDPProtocol(self)
 def __init__(self, dir, method,roi,method2, parent=None):
     super(Video_Player, self).__init__()
     self.video = cv2.VideoCapture(dir)
     self.last_frame = np.zeros((1, 1))
     self.num_frames = int(self.video.get(cv2.CAP_PROP_FRAME_COUNT))
     self.localize_method = method
     self.exctact_method = method2
     self.roi = roi
     self.count = 0
     self.stopped = True
     self.x = 0
     self.y = 0
     self.width = 0
     self.height = 0
     self.flag = 0
     self.tracker = Tracker.Tracker(20)
     self.syntactic = Syntactic_analysator.Syntatic_analysator()
     filename = 'finalized_model6.sav'
     filename3 = 'ocr_model.sav'
     self.loaded_model = pickle.load(open(filename, 'rb'))
     self.ocr = pickle.load(open(filename3, 'rb'))
     print(self.loaded_model)
     self.class_names = [ '0', '1', '2', '3', '4', '5', '6', '7', '8',
                '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
                'L', 'M', 'N', 'O', 'P', 'R','S', 'T',  'U', 'V', 'W',
                'X', 'Y', 'Z','']
Esempio n. 15
0
    def __init__(self):
        #self.node_name = rospy.get_name()
        #rospy.loginfo("[%s] Initializing " %(self.node_name))
        self.bridge = CvBridge()
        self.is_compressed = False
        # Image definition
        self.width = 640
        self.height = 480
        self.labels = ['background', 'person', 'palm']
        self.prob_threshold = 0.5
        self.objects = []
        self.net = build_ssd('test', 300, len(self.labels))  # initialize SSD
        self.net.load_weights(
            '/home/user/argbot/catkin_ws/src/track/src/argbot_58000.pth')
        if torch.cuda.is_available():
            self.net = self.net.cuda()

        #img = cv2.imread("radio.jpg")
        self.image_pub = rospy.Publisher("/predict_img", Image, queue_size=1)
        self.image_sub = rospy.Subscriber("/camera/color/image_raw",
                                          Image,
                                          self.img_cb,
                                          queue_size=1,
                                          buff_size=2**24)
        self.tracker = Tracker.Tracker()
        self.path = []
Esempio n. 16
0
def parse_get_tracker_term_item(dict_input, user_id):
    term_uuid = dict_input.get('uuid', None)
    res = check_term_uuid_valid_access(term_uuid, user_id)
    if res:
        return res

    date_from = dict_input.get('date_from', None)
    date_to = dict_input.get('date_to', None)

    if date_from is None:
        date_from = get_tracked_term_first_seen(term_uuid)
        if date_from:
            date_from = date_from[0]

    if date_to is None:
        date_to = date_from

    if date_from > date_to:
        date_from = date_to

    all_item_id = Tracker.get_tracker_items_by_daterange(
        term_uuid, date_from, date_to)
    all_item_id = Item.get_item_list_desc(all_item_id)

    res_dict = {}
    res_dict['uuid'] = term_uuid
    res_dict['date_from'] = date_from
    res_dict['date_to'] = date_to
    res_dict['items'] = all_item_id
    return (res_dict, 200)
Esempio n. 17
0
def load_video_summary(video, base_path=DATA_DIR, **kwargs):
    df, X, Y, S, N, W, H = t.read_video_summary(video,
                                                base_path=base_path,
                                                **kwargs)
    with open(base_path / f'{video:s}_lanes.pkl', 'rb') as f:
        lanes = pkl.load(f)
    return df, X, Y, S, N, W, H, lanes
Esempio n. 18
0
    def __init__(self, object_name, frame_dims):
        """Creates the object and generates the histogram for the object to be tracked (object_name)."""
        self.object_name = object_name
        self.frameDims = frame_dims
        self.fWidth, self.fHeight = frame_dims
        #Full window, useful for reseting track windows
        self.full_track_window = (0,0,self.fWidth,self.fHeight)
        
        fullStr = object_name + ".jpg"
        path = ".." + os.path.join(os.sep, "res", "images", fullStr)

        try:
            self.object_image = cv2.imread(path)
        except:
            print object_name + " image could not be read"
            
        self.averageColor = self.calcAverageColor()        
        
        object_hsv = cv2.cvtColor(self.object_image, cv2.COLOR_BGR2HSV)
        mask = cv2.inRange(object_hsv, np.array((0., 50., 30.)), np.array((255., 255., 255.)))
        self.hist = cv2.calcHist([object_hsv], [0], mask, [16], [0,255])
        cv2.normalize(self.hist, self.hist, 0, 255, cv2.NORM_MINMAX)
        
        #Contains trackers for objects already found by the searcher
        self.tracking = []
        
        #Tracker that is looking for new objects
        self.searcher = Tracker(self.frameDims, self.full_track_window, False)
Esempio n. 19
0
def createTracker():
    print("Creating a Tracker...")
    t = Tracker.Tracker()
    sleep(1)

    print("Tracker created with the following ID: ", t.getID())
    sleep(1)
    createTrackerMenu(t)
Esempio n. 20
0
def delete_term(term_uuid):
    term = r_serv_term.hget('tracker:{}'.format(term_uuid), 'tracked')
    term_type = r_serv_term.hget('tracker:{}'.format(term_uuid), 'type')
    level = r_serv_term.hget('tracker:{}'.format(term_uuid), 'level')
    r_serv_term.srem('all:tracker_uuid:{}:{}'.format(term_type, term),
                     term_uuid)
    # Term not tracked by other users
    if not r_serv_term.exists('all:tracker_uuid:{}:{}'.format(term_type,
                                                              term)):
        r_serv_term.srem('all:tracker:{}'.format(term_type), term)

        # toggle refresh module tracker list/set
        r_serv_term.set('tracker:refresh:{}'.format(term_type), time.time())

    if level == '0':  # user only
        user_id = term_type = r_serv_term.hget('tracker:{}'.format(term_uuid),
                                               'user_id')
        r_serv_term.srem('user:tracker:{}'.format(user_id), term_uuid)
        r_serv_term.srem('user:tracker:{}:{}'.format(user_id, term_type),
                         term_uuid)
    elif level == '1':  # global
        r_serv_term.srem('global:tracker', term_uuid)
        r_serv_term.srem('global:tracker:{}'.format(term_type), term_uuid)

    # delete metatadata
    r_serv_term.delete('tracker:{}'.format(term_uuid))

    # remove tags
    r_serv_term.delete('tracker:tags:{}'.format(term_uuid))

    # remove mails
    r_serv_term.delete('tracker:mail:{}'.format(term_uuid))

    # remove item set
    all_item_date = r_serv_term.zrange('tracker:stat:{}'.format(term_uuid), 0,
                                       -1)
    for date in all_item_date:
        r_serv_term.delete('tracker:item:{}:{}'.format(term_uuid, date))
    r_serv_term.delete('tracker:stat:{}'.format(term_uuid))

    if term_type == 'yara':
        # delete custom rule
        if not Tracker.is_default_yara_rule(term):
            filepath = Tracker.get_yara_rule_file_by_tracker_name(term)
            if filepath:
                os.remove(filepath)
Esempio n. 21
0
def add_tracked_term(term,
                     term_type,
                     user_id,
                     level,
                     tags,
                     mails,
                     description,
                     dashboard=0):

    term_uuid = str(uuid.uuid4())

    # YARA
    if term_type == 'yara_custom' or term_type == 'yara_default':
        term = Tracker.save_yara_rule(term_type, term, tracker_uuid=term_uuid)
        term_type = 'yara'

    # create metadata
    r_serv_term.hset('tracker:{}'.format(term_uuid), 'tracked',
                     term)  # # TODO: use hash
    r_serv_term.hset('tracker:{}'.format(term_uuid), 'type', term_type)
    r_serv_term.hset('tracker:{}'.format(term_uuid), 'date',
                     datetime.date.today().strftime("%Y%m%d"))
    r_serv_term.hset('tracker:{}'.format(term_uuid), 'user_id', user_id)
    r_serv_term.hset('tracker:{}'.format(term_uuid), 'level', level)
    r_serv_term.hset('tracker:{}'.format(term_uuid), 'dashboard', dashboard)

    if description:
        r_serv_term.hset('tracker:{}'.format(term_uuid), 'description',
                         description)

    # create all term set
    r_serv_term.sadd('all:tracker:{}'.format(term_type), term)

    # create term - uuid map
    r_serv_term.sadd('all:tracker_uuid:{}:{}'.format(term_type, term),
                     term_uuid)

    # add display level set
    if level == 0:  # user only
        r_serv_term.sadd('user:tracker:{}'.format(user_id), term_uuid)
        r_serv_term.sadd('user:tracker:{}:{}'.format(user_id, term_type),
                         term_uuid)
    elif level == 1:  # global
        r_serv_term.sadd('global:tracker', term_uuid)
        r_serv_term.sadd('global:tracker:{}'.format(term_type), term_uuid)

    # create term tags list
    for tag in tags:
        r_serv_term.sadd('tracker:tags:{}'.format(term_uuid), escape(tag))

    # create term tags mail notification list
    for mail in mails:
        r_serv_term.sadd('tracker:mail:{}'.format(term_uuid), escape(mail))

    # toggle refresh module tracker list/set
    r_serv_term.set('tracker:refresh:{}'.format(term_type), time.time())

    return term_uuid
Esempio n. 22
0
def get_json_retro_hunt_nb_items_by_date():
    date_from = request.args.get('date_from')
    date_to = request.args.get('date_to')

    if date_from:
        date_from = date_from.replace('-', '')
    if date_to:
        date_to = date_to.replace('-', '')

    task_uuid = request.args.get('uuid')

    if date_from and date_to:
        res = Tracker.get_retro_hunt_nb_item_by_day([task_uuid],
                                                    date_from=date_from,
                                                    date_to=date_to)
    else:
        res = Tracker.get_retro_hunt_nb_item_by_day([task_uuid])
    return jsonify(res)
Esempio n. 23
0
	def splitTracker(self, tracker):
		"""Using the info from tracker, it splits the tracker into 4 new trackers with each having a trackbox of the 4 quadrants of the original tracker."""
		c,r,w,h = tracker.getTrackWindow()		
		w1 = w // 2
		w2 = w - w1
		h1 = h // 2
		h2 = h - h1		
		for newBox in [(c, r, w1, h1), (c+w1+1, r, w2, h1), (c, r+h1+1, w1, h2), (c+w1+1, r+h1+1, w2, h2)]:
			self.tracking.append(Tracker(newBox, True))
Esempio n. 24
0
def retro_hunt_show_task():
    task_uuid = request.args.get('uuid', None)

    date_from = request.args.get('date_from')
    date_to = request.args.get('date_to')
    if date_from:
        date_from = date_from.replace('-', '')
    if date_to:
        date_to = date_to.replace('-', '')

    res = Tracker.api_check_retro_hunt_task_uuid(task_uuid)
    if res:
        return create_json_response(res[0], res[1])

    dict_task = Tracker.get_retro_hunt_task_metadata(task_uuid,
                                                     date=True,
                                                     progress=True,
                                                     creator=True,
                                                     sources=True,
                                                     tags=True,
                                                     description=True)
    rule_content = Tracker.get_yara_rule_content(dict_task['rule'])

    if date_from:
        res = Tracker.api_get_retro_hunt_items({
            'uuid': task_uuid,
            'date_from': date_from,
            'date_to': date_to
        })
        if res[1] != 200:
            return create_json_response(res[0], res[1])
        dict_task['items'] = res[0]['items']
        dict_task['date_from_input'] = res[0]['date_from']
        dict_task['date_to_input'] = res[0]['date_to']
    else:
        dict_task['items'] = []
        dict_task['date_from_input'] = dict_task['date_from']
        dict_task['date_to_input'] = dict_task['date_to']

    return render_template("show_retro_hunt.html",
                           dict_task=dict_task,
                           rule_content=rule_content,
                           bootstrap_label=bootstrap_label)
Esempio n. 25
0
    def set_annotation(self, annotation):

        # weak reference to annotation
        self.annotation = weakref.ref(annotation)

        # assign tracker to this database
        self.tracker = Tracker.Tracker(self.annotation())

        # reset the selected class
        self.class_name = None
Esempio n. 26
0
def test1(files):
    tr = Tracker()
    n = 4
    for f in files:
        mm = MMap(f)
        track = Track(mm.loop(), 8)
        tr.append(track)
    for track in tr:
        print track
        track[randrange(n)] = 1.0
    tr.start()
    while tr.send():
        for track in tr:
            track.send()
    tr.stop()
    sleep(1)
Esempio n. 27
0
def edit_tracked_menu():
    user_id = current_user.get_id()
    tracker_uuid = request.args.get('uuid', None)

    res = Term.check_term_uuid_valid_access(
        tracker_uuid, user_id)  # check if is author or admin
    if res:  # invalid access
        return Response(json.dumps(res[0], indent=2, sort_keys=True),
                        mimetype='application/json'), res[1]

    dict_tracker = Tracker.get_tracker_metadata(tracker_uuid,
                                                user_id=True,
                                                level=True,
                                                description=True,
                                                tags=True,
                                                mails=True,
                                                sources=True,
                                                webhook=True)
    dict_tracker['tags'] = ' '.join(dict_tracker['tags'])
    dict_tracker['mails'] = ' '.join(dict_tracker['mails'])

    if dict_tracker['type'] == 'set':
        dict_tracker['tracker'], dict_tracker['nb_words'] = dict_tracker[
            'tracker'].split(';')
        dict_tracker['tracker'] = dict_tracker['tracker'].replace(',', ' ')
    elif dict_tracker['type'] == 'yara':  #is_valid_default_yara_rule
        if Tracker.is_default_yara_rule(dict_tracker['tracker']):
            dict_tracker['yara_file'] = dict_tracker['tracker'].split('/')
            dict_tracker['yara_file'] = dict_tracker['yara_file'][
                -2] + '/' + dict_tracker['yara_file'][-1]
            dict_tracker['content'] = None
        else:
            dict_tracker['yara_file'] = None
            dict_tracker['content'] = Tracker.get_yara_rule_content(
                dict_tracker['tracker'])

    return render_template(
        "edit_tracker.html",
        dict_tracker=dict_tracker,
        all_sources=item_basic.get_all_items_sources(r_list=True),
        all_yara_files=Tracker.get_all_default_yara_files())
Esempio n. 28
0
 def locationTracker(self):
     '''
     Launches window to locate new point from reference point
     '''
     if self.reference and self.scale and self.units:
         self.referenceTable = ReferenceSelectionWindow(self.reference)
         if self.referenceTable.exec_():
             self.locationTrace = Tracker.TrackerLoc(
                 self.referenceTable.selectedData,
                 self.scale,
                 self.units,
                 parent=self)
Esempio n. 29
0
def show_car(video,
             car,
             crop=True,
             constraints_level=2,
             videos_path=Path(r'd:\media\videos\ayalon'),
             **kwargs):
    video = video if video.endswith('.mp4') else video + '.mp4'
    _, X, Y, _, _, _, _, _ = load_video_summary(video[:-4])
    # import pdb
    # pdb.set_trace()
    X = pd.DataFrame(t.m2p_x(X, video), columns=X.columns)
    Y = pd.DataFrame(t.m2p_y(Y, video), columns=Y.columns)
    area = t.get_cropped_frame_area(video) if crop else None
    model = t.get_detector(area,
                           constraints_level=constraints_level,
                           verbose=0)
    t.visualize_video(model,
                      str(videos_path / video),
                      X,
                      Y,
                      car=str(car),
                      area=area,
                      min_hits=1,
                      **kwargs)
    del model
Esempio n. 30
0
def qplots(X,
           quants=np.arange(101),
           ylab='',
           tit='',
           count_nas=True,
           ax=None,
           showmeans=True,
           remove_na_rows=True,
           logscale=False,
           assume_sorted=False):
    quants = np.array(quants)
    colors = t.get_colors(X.shape[1])
    if ax is None:
        ax = plt.gca()

    n_orig = X.shape[0]
    if remove_na_rows:
        X = X[X.notnull().all(axis=1)]

    if count_nas:
        if remove_na_rows:
            cnt = f'Valid values: {len(X):d}/{n_orig:d} ({100*len(X)/n_orig:.1f}%)'
        else:
            cnt = f'(values: {len(X):d})'
        if tit:
            tit += f'\n{cnt:s}'
        else:
            tit = cnt

    for i, c in enumerate(X.columns):
        x = X[c]
        if not remove_na_rows:
            x = x[x.notnull()]
        if not assume_sorted:
            x = np.sort(x)
        color = colors[i]
        if showmeans:
            ax.axhline(np.mean(x), linestyle=':', color=color)
        ax.plot(quants,
                x[np.array(quants / 100 * (len(x) - 1), dtype=int)],
                '.-',
                color=color,
                label=c)
    ax.set_xlabel('Quantile [%]')
    ax.set_ylabel(ylab)
    ax.set_title(tit)
    ax.set_xlim((quants.min(), quants.max()))
    if logscale:
        ax.set_yscale('log')
    ax.grid()
    ax.legend()
Esempio n. 31
0
def test1(files):
  tr=Tracker()
  n=4
  for f in files:
    mm=MMap(f)
    track=Track(mm.loop(),8) 
    tr.append( track )
  for track in tr:
    print track
    track[ randrange(n) ] = 1.0
  tr.start()
  while tr.send():
    for track in tr:
      track.send()
  tr.stop()
  sleep(1)
Esempio n. 32
0
def yara_rules_match(data):
    #print(data)
    tracker_uuid = data['namespace']

    item_date = item_basic.get_item_date(item_id)
    Tracker.add_tracked_item(tracker_uuid, item_id, item_date)

    # Tags
    tags_to_add = Tracker.get_tracker_tags(tracker_uuid)
    for tag in tags_to_add:
        msg = '{};{}'.format(tag, item_id)
        p.populate_set_out(msg, 'Tags')

    # Mails
    mail_to_notify = Tracker.get_tracker_mails(tracker_uuid)
    if mail_to_notify:
        mail_subject = Tracker.get_email_subject(tracker_uuid)
        mail_body = mail_body_template.format(data['rule'], item_id,
                                              full_item_url, item_id)
    for mail in mail_to_notify:
        NotificationHelper.sendEmailNotification(mail, mail_subject, mail_body)

    return yara.CALLBACK_CONTINUE
Esempio n. 33
0
async def testiz(path):
    tor = Torrent(path)
    print(tor.get_torrent_data())
    print(tor.get_torrent_ind_size())
    print(tor.get_torrent_piece_length())
    print(tor.get_torrent_name().decode())
    for tracker in tor.get_torrent_announce_list():
        test_tracker = Tracker.Tracker_udp(tor, tracker[0])
        try:
            loop.run_until_complete(test_peer_comm(test_tracker))
            break
        except Exception as e:
            print("tracker {0} did not work, exception was: {1}".format(tracker[0], e))
    loop.close()
    print("finishing")
Esempio n. 34
0
reload(Placer)

import Tracker
reload(Tracker)

import Trackreader
reload(Trackreader)
 

d=App.newDocument("Unbenannt")
b=App.activeDocument().addObject("Part::Box","Box")


r=Placer.createPlacer("BoxPlacer",b)

t=Tracker.createTracker("BoxTracker",r,"/tmp/tracker")

m=Animation.createManager()

m.intervall = 100
m.sleeptime = 0.01
m.addObject(r)
m.addObject(t)
m.Proxy.run()


path=t.ViewObject.Proxy.showpath()


import Trackreader
reload(Trackreader)
Esempio n. 35
0
        except Exception as e:
            logging.debug("NULLA SELEZIONATO:  " + str(e))

    def btn_rimuovi_file_click(self):
        try:
            index = self.list_file.curselection()[0]
            del self.file_aggiunti[index]
            self.list_file.delete(index, index)
            logging.debug("rimosso: " + str(index))
        except Exception as e:
            logging.debug("NULLA SELEZIONATO")


if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    tracker = False

    if tracker:
        tcpServer = Tracker(Utility.database, Utility.IPv4_TRACKER + '|' + Utility.IPv6_TRACKER, Utility.PORT_TRACKER)
        tcpServer.run()

    else:
        root = Tk()
        root.geometry("800x600")
        app = Window(root=root)

        tcpServer = Tracker(Utility.database, Utility.IP_MY,  Utility.PORT_MY)
        tcpServer.start()

        root.mainloop()
Esempio n. 36
0
reload(Animation)

import Placer
reload(Placer)

import Tracker
reload(Tracker)
 

d=App.newDocument("Unbenannt")
b=App.activeDocument().addObject("Part::Box","Box")


r=Placer.createPlacer("BoxPlacer",b)

t=Tracker.createTracker("BoxTracker",r)

m=createManager()
m.intervall = 100
m.sleeptime = 0.01
m.addObject(r)
m.addObject(t)
m.Proxy.run()


uu=t.ViewObject.Proxy.showpath()

assert(isequal(uu.Shape.Length,21.5495896498609))

#App.closeDocument("Unbenannt")
Esempio n. 37
0
class TargetScanner(object):
    def __init__(self, object_name, frame_dims):
        """Creates the object and generates the histogram for the object to be tracked (object_name)."""
        self.object_name = object_name
        self.frameDims = frame_dims
        self.fWidth, self.fHeight = frame_dims
        #Full window, useful for reseting track windows
        self.full_track_window = (0,0,self.fWidth,self.fHeight)
        
        fullStr = object_name + ".jpg"
        path = ".." + os.path.join(os.sep, "res", "images", fullStr)

        try:
            self.object_image = cv2.imread(path)
        except:
            print object_name + " image could not be read"
            
        self.averageColor = self.calcAverageColor()        
        
        object_hsv = cv2.cvtColor(self.object_image, cv2.COLOR_BGR2HSV)
        mask = cv2.inRange(object_hsv, np.array((0., 50., 30.)), np.array((255., 255., 255.)))
        self.hist = cv2.calcHist([object_hsv], [0], mask, [16], [0,255])
        cv2.normalize(self.hist, self.hist, 0, 255, cv2.NORM_MINMAX)
        
        #Contains trackers for objects already found by the searcher
        self.tracking = []
        
        #Tracker that is looking for new objects
        self.searcher = Tracker(self.frameDims, self.full_track_window, False)
        
    
    def calcAverageColor(self):
            """Calculates the average color of the object to be tracked."""
            imgWidth, imgHeight, imgDepth = self.object_image.shape
            area = imgWidth * imgHeight
            return (int(np.sum(self.object_image[:,:,0]) / area),
                    int(np.sum(self.object_image[:,:,1]) / area),
                    int(np.sum(self.object_image[:,:,2]) / area))     
        
        
    def scan(self, frame, hsv_frame, mask):
        """Updates all the of trackers for identified objects and updates the searcher which is looking for new objects."""
        bproj = cv2.calcBackProject([hsv_frame], [0], self.hist, [0,255], 1)        
        bproj &= mask        
        for index, tracker in enumerate(self.tracking):
            original_bproj = bproj.copy()
            box, bproj, split = tracker.update(bproj)
            coords, dims, theta = box
            w,h = dims
            if split:
                self.splitTracker(tracker)
                del self.tracking[index]
                bproj = original_bproj
            if tracker.hasFound() and w > 0 and h > 0:
                cv2.ellipse(frame, box, self.averageColor, 2)
            else:
                del self.tracking[index]                
        box, bproj, split = self.searcher.update(bproj.copy())        
        if split:
            self.splitTracker(self.searcher)
            self.searcher = Tracker(self.frameDims, self.full_track_window, found = False)
        if self.searcher.hasFound(): # If searcher finds an object, start tracking that object and make a new searcher
            self.tracking.append(self.searcher)
            self.searcher = Tracker(self.frameDims, self.full_track_window, found = False)            
        return frame

    
    def getTrackingInfo(self):
        """Returns the tracking info ((x, y,width, height), matchScore) about all the currently identified objects."""
        info = []
        for tracker in self.tracking:
            if tracker.hasFound():
                c,r,w,h = tracker.getTrackWindow()
                x,y = tracker.getCenter()
                score = tracker.getMatchLevel()
                info.append(((x,y,w,h), score))
        return info
        
    
    def splitTracker(self, tracker):
        """Using the info from tracker, it splits the tracker into 4 new trackers with each having a trackbox of the 4 quadrants of the original tracker."""
        #Useful if tracked objects pass by each other
        c,r,w,h = tracker.getTrackWindow()        
        w1 = w // 2
        w2 = w - w1
        h1 = h // 2
        h2 = h - h1        
        for newBox in [(c, r, w1, h1), (c+w1+1, r, w2, h1), (c, r+h1+1, w1, h2), (c+w1+1, r+h1+1, w2, h2)]:
            self.tracking.append(Tracker(self.frameDims, newBox, True))
Esempio n. 38
0
import math, hashlib


# Local imports
import eventListener
import githubClient
from polymer_bricks_api_messages import ComponentBasicInfo
from polymer_bricks_api_messages import ComponentDetails
from core_methods_exceptions import NotFoundException, RateNotUpdatedException, \
ComponentAlreadyStoredException
# Add the folder lib to make a local import
sys.path.insert(0, 'lib')
import Tracker

# Tracker for Google Analytics
tracker = Tracker.create('UA-55678584-1', name='myTracker', use_post=True)
  
# Generates the sha512 id corresponding to the full_name of the repo
def generateRepoHash(repoFullName):
  m = hashlib.sha256()
  m.update(repoFullName)
  return m.hexdigest()


"""Core methods """
# Method to get the user rating in the RPC message relative to a component
def getUserRating(idComponent, userId):
  rating = 0.0
  userRating = UserRating.query(ndb.AND(UserRating.google_user_id==userId, UserRating.repo_full_name_id == idComponent)).get()
  #print "DEBUG "  + str(userRating.rating_value)
  if not userRating == None: