Exemplo n.º 1
0
def run(sv):

    #initialize the board
    current_board = board.Board(sv.board_h, sv.board_w, sv.mapInfo,
                                sv.startingPosition)
    status, updates = sv.update()
    current_board.updateBoard(updates)
    heuristicHistory = {}
    clock = Clock(TIME_LIMIT)
    while True:
        #print('Board :', current_board.getBoard())
        start_time = time.time()
        clock.startClock()
        minimax.nb_nodes_explore = 0
        minimax.nb_cuts = 0

        #perform tree search throw minimax and reprise optim pos
        exploredPositions = {}
        #current_pos = current_board.getCurrentPositions()
        #as new positions are sorted by pos number we do the same for the current_pos
        current_pos = list(
            dict(
                sorted(current_board.getOurDict().items(),
                       key=lambda kv: kv[1],
                       reverse=True)).keys())

        new_pos = minimax(current_board, exploredPositions, heuristicHistory,
                          clock)[0]

        #if we have more new pos than existing, this is a split to manage
        if len(new_pos) > len(current_pos):
            for i in range(len(new_pos) - len(current_pos)):
                current_pos.append(current_pos[0])
        print("current_pos", current_pos)
        print("new pos", new_pos)

        #move player
        sv.movePlayers_split_Leo(new_pos)
        end_time = time.time()
        print("Time Elapsed : " + str(end_time - start_time))
        print("Number of nodes explored :", minimax.nb_nodes_explore)
        print("Number of cuts performed :", minimax.nb_cuts)

        status, updates = sv.update()
        #print("update", updates)
        current_board.updateBoard(updates)
        #print('new board', current_board.getBoard())

        #input('are you ready ?')
        if status == "END" or status == "BYE":
            break
    print('game ended')
Exemplo n.º 2
0
def run(sv):
    # initialize the board
    current_board = board_split.Board(sv.board_h, sv.board_w, sv.mapInfo,
                                      sv.startingPosition)
    status, updates = sv.update()
    current_board.updateBoard(updates)

    heuristicHistory = {}
    clock = Clock(1.95)
    while True:
        # print('Board :', current_board.getBoard())
        start_time = time.time()
        clock.startClock()
        minimax.nb_nodes_explore = 0
        minimax.nb_cuts = 0

        # perform tree search throw minimax and reprise optim pos
        source_pos = []
        number_moved = []
        destination_pos = []
        for current_position in current_board.getCurrentDict():
            exploredPositions = {}
            new_pos = [
                minimax(current_board, exploredPositions, heuristicHistory,
                        clock, current_position)[0]
            ]
            source_pos.append(current_position)
            number_moved.append(
                current_board.getCurrentDict()[tuple(current_position)])
            destination_pos.append(new_pos[0])
            print("moved from %s to %s" % (current_position, new_pos))

        # move player
        sv.movePlayers(source_pos, number_moved, destination_pos)
        end_time = time.time()
        print("Time Elapsed : " + str(end_time - start_time))
        print("Number of nodes explored :", minimax.nb_nodes_explore)
        print("Number of cuts performed :", minimax.nb_cuts)

        status, updates = sv.update()
        # print("update", updates)
        current_board.updateBoard(updates)
        # print('new board', current_board.getBoard())
        # input('are you ready ?')
        if status == "END" or status == "BYE":
            break
        # time.sleep(1)
    print('game ended')
Exemplo n.º 3
0
def run(sv):

    #initialize the board
    current_board = board.Board(sv.board_h, sv.board_w, sv.mapInfo,
                                sv.startingPosition)
    status, updates = sv.update()
    current_board.updateBoard(updates)

    heuristicHistory = {}
    clock = Clock(1.95)
    while True:
        #print('Board :', current_board.getBoard())
        start_time = time.time()
        clock.startClock()
        minimax.nb_nodes_explore = 0
        minimax.nb_cuts = 0

        #perform tree search throw minimax and reprise optim pos
        exploredPositions = {}
        possibleMovesScores = []
        possibleMovesScores5 = [[0]]
        Smart_score = 0
        new_pos = [
            minimax(current_board, exploredPositions, heuristicHistory,
                    possibleMovesScores, possibleMovesScores5, Smart_score,
                    clock)[0]
        ]
        print("new pos", new_pos)

        #move player
        sv.movePlayers(current_board.getCurrentPositions(),
                       current_board.getCurrentUnitsNumber(), new_pos)
        end_time = time.time()
        print("Time Elapsed : " + str(end_time - start_time))
        print("Number of nodes explored :", minimax.nb_nodes_explore)
        print("Number of cuts performed :", minimax.nb_cuts)

        status, updates = sv.update()
        #print("update", updates)
        current_board.updateBoard(updates)
        #print('new board', current_board.getBoard())

        #input('are you ready ?')
        if status == "END" or status == "BYE":
            break
        #time.sleep(1)
    print('game ended')
Exemplo n.º 4
0
 def setup(self, **params):
     self.log.info("Setting up experiment...")
     self.log_block = dict(instance=None, method=None, replication=None)
     self.clock = Clock()
     self.params = Namespace(params)
     self.params.experiment = self
     self.params.log = self.log
     self.on_setup()
Exemplo n.º 5
0
async def test_rate(no_sleep):
    # reset call count
    no_sleep.call_count = 0

    # ensure sleep duration is rate
    c = Clock(100, rate=10)
    ret = await c.start()

    no_sleep.assert_called_with(10)
    assert no_sleep.call_count == 10
Exemplo n.º 6
0
async def test_early_exit():
    # ensure early exit works
    cb = AsyncMock()
    _test_resp = {"test": "some-ret-value"}
    cb.return_value = _test_resp

    c = Clock(5, condition=cb)
    ret = await c.start()
    assert ret == _test_resp
    assert c.integrator == 1
Exemplo n.º 7
0
async def test_callbacks():
    # ensure callbacks work
    cb = AsyncMock()
    cb.return_value = False

    c = Clock(5, condition=cb)
    ret = await c.start()

    assert ret == c.default_return
    cb.assert_has_calls([call(4 - i) for i in range(5)])
Exemplo n.º 8
0
def test_constructor():
    # ensure interface values stored
    c = Clock(5)

    assert c.duration == 5
    assert c.condition == None
    assert c.integrator == 0
    assert c.default_return == {}

    # ensure default_return is stored
    c = Clock(5, default_return={"test": "value"})
    assert c.default_return == {"test": "value"}

    # test negative
    with pytest.raises(AssertionError):
        Clock(-5)

    # test 0
    with pytest.raises(AssertionError):
        Clock(0)

    # test rate parameter
    with pytest.raises(AssertionError):
        Clock(1, rate=5)

    c = Clock(5, rate=2)
    assert c.rate == 2
Exemplo n.º 9
0
    def test_obb(self):

        from deepsort_tracker import DeepSort
        from utils.clock import Clock

        import cv2
        import numpy as np

        clock = Clock()
        tracker = DeepSort(max_age=30,
                           nn_budget=100,
                           nms_max_overlap=1.0,
                           clock=clock,
                           embedder=True,
                           polygon=True)

        tic = time.perf_counter()

        print()
        print('FRAME1')
        frame1 = np.ones((1080, 1920, 3), dtype=np.uint8) * 255
        detections1 = [[[0, 0, 10, 0, 10, 10, 0, 10],
                        [20, 20, 30, 20, 30, 30, 20, 30]], [0, 1], [0.5, 0.5]]
        tracks = tracker.update_tracks(detections1, frame=frame1)

        correct_ans = [
            np.array([0., 0., 11., 11.]),
            np.array([20., 20., 11., 11.])
        ]
        for track, ans in zip(tracks, correct_ans):
            print(track.track_id)
            ltwh = track.to_ltwh()
            print(ltwh)
            np.testing.assert_allclose(ltwh, ans)

        print()
        print('FRAME2')
        # assume new frame
        frame2 = frame1
        detections2 = [[[0, 0, 10, 0, 15, 10, 0, 15],
                        [25, 20, 30, 20, 30, 30, 25, 30]], [0, 1], [0.5, 0.6]]
        tracks = tracker.update_tracks(detections2, frame=frame2)

        correct_ans = [
            np.array([0., 0., 15.33884298, 15.33884298]),
            np.array([22.21844112, 20., 10.90196074, 11.])
        ]
        for track, ans in zip(tracks, correct_ans):
            print(track.track_id)
            ltwh = track.to_ltwh()
            print(ltwh)
            np.testing.assert_allclose(ltwh, ans)

        print()
        print('FRAME3')
        # assume new frame
        frame3 = frame1
        detections3 = [[[0, 0, 10, 0, 15, 10, 10, 15],
                        [20, 20, 30, 20, 30, 30, 25, 30]], [0, 3], [0.5, 0.6]]
        tracks = tracker.update_tracks(detections3, frame=frame3)

        correct_ans = [
            np.array([0., 0., 16.12303476, 16.12303476]),
            np.array([20.63971341, 20., 10.90477995, 11.])
        ]
        for track, ans in zip(tracks, correct_ans):
            print(track.track_id)
            ltwh = track.to_ltwh()
            print(ltwh)
            np.testing.assert_allclose(ltwh, ans)

        print()
        print('FRAME4')
        # assume new frame
        frame4 = frame1
        detections4 = [[[0.0, 5.0, 15.0, 5.0, 15.0, 10.0, 10.0, 25.0],
                        [20.0, 20.0, 30.0, 20.0, 30.0, 30.0, 25.0, 30.0]],
                       [3, 3], [0.9, 0.6]]
        tracks = tracker.update_tracks(detections4, frame=frame4)

        correct_ltwh_ans = [
            np.array([-1.65656289, 3.48914218, 19.63792898, 19.81394538]),
            np.array([20.10337142, 20., 10.90833262, 11.])
        ]
        correct_orig_ltwh_ans = [[0., 5., 16., 21.], [20., 20., 11., 11.]]
        correct_poly_ans = detections4[0]

        for track, ltwh_ans, orig_ltwh_ans, poly_ans in zip(
                tracks, correct_ltwh_ans, correct_orig_ltwh_ans,
                correct_poly_ans):
            print(track.track_id)

            ltwh = track.to_ltwh()
            print(ltwh)
            np.testing.assert_allclose(ltwh, ltwh_ans)

            orig_ltwh = track.to_ltwh(orig=True)
            print(orig_ltwh)
            np.testing.assert_allclose(orig_ltwh, orig_ltwh_ans)

            poly = track.get_det_supplementary()
            print(poly)
            np.testing.assert_allclose(poly, poly_ans)

        toc = time.perf_counter()
        print(f'Avrg Duration per update: {(toc-tic)/4}')

        return True
Exemplo n.º 10
0
    def test_hbb(self):

        from deepsort_tracker import DeepSort
        from utils.clock import Clock

        import cv2
        import numpy as np

        clock = Clock()
        # tracker = DeepSort(max_age = 30, nn_budget=100, nms_max_overlap=1.0, clock=clock, embedder=False)
        tracker = DeepSort(max_age=30,
                           nn_budget=100,
                           nms_max_overlap=1.0,
                           clock=clock,
                           embedder=True)

        tic = time.perf_counter()
        print()
        print('FRAME1')
        frame1 = np.ones((1080, 1920, 3), dtype=np.uint8) * 255
        detections1 = [([0, 0, 50, 50], 0.5, 'person'),
                       ([50, 50, 50, 50], 0.5, 'person')]
        embeds1 = [
            np.array([0.1, 0.1, 0.1, 0.1]),
            np.array([-1.0, 1.0, 0.5, -0.5])
        ]
        # tracks = tracker.update_tracks(detections1, embeds=embeds1)
        tracks = tracker.update_tracks(detections1, frame=frame1)
        for track in tracks:
            print(track.track_id)
            print(track.to_tlwh())

        print()
        print('FRAME2')
        # assume new frame
        frame2 = frame1
        detections2 = [([10, 10, 60, 60], 0.8, 'person'),
                       ([60, 50, 50, 50], 0.7, 'person')]
        embeds2 = [
            np.array([0.1, 0.1, 0.1, 0.1]),
            np.array([-1.1, 1.0, 0.5, -0.5])
        ]
        # tracks = tracker.update_tracks(detections2, embeds=embeds2)
        tracks = tracker.update_tracks(detections2, frame=frame2)
        for track in tracks:
            print(track.track_id)
            print(track.to_tlwh())

        print()
        print('FRAME3')
        # assume new frame
        frame3 = frame1
        detections3 = [([20, 20, 70, 70], 0.8, 'person'),
                       ([70, 50, 50, 50], 0.7, 'person')]
        embeds3 = [
            np.array([0.1, 0.1, 0.1, 0.1]),
            np.array([-1.1, 1.0, 0.5, -0.5])
        ]
        # tracks = tracker.update_tracks(detections3, embeds=embeds3)
        tracks = tracker.update_tracks(detections3, frame=frame3)
        for track in tracks:
            print(track.track_id)
            print(track.to_tlwh())

        print()
        print('FRAME4')
        # assume new frame
        frame4 = frame1
        detections4 = [([10, 10, 60, 60], 0.8, 'person')]
        embeds4 = [np.array([0.1, 0.1, 0.1, 0.1])]
        # tracks = tracker.update_tracks(detections4, embeds=embeds4)
        tracks = tracker.update_tracks(detections4, frame=frame4)
        for track in tracks:
            print(track.track_id)
            print(track.to_tlwh())

        toc = time.perf_counter()
        print(f'Avrg Duration per update: {(toc-tic)/4}')
        return True
Exemplo n.º 11
0
    def point_cloud_callback(self, cloud_msg):
        """

        :param cloud_msg:
        :return:
        """

        # cv_image = self._cv_bridge.imgmsg_to_cv2(image_msg, "bgr8")
        # # copy from
        # # classify_image.py
        # image_data = cv2.imencode('.jpg', cv_image)[1].tostring()
        # # Creates graph from saved GraphDef.
        # softmax_tensor = self._session.graph.get_tensor_by_name('softmax:0')
        # predictions = self._session.run(
        #     softmax_tensor, {'DecodeJpeg/contents:0': image_data})
        # predictions = np.squeeze(predictions)
        # # Creates node ID --> English string lookup.
        # node_lookup = classify_image.NodeLookup()
        # top_k = predictions.argsort()[-self.use_top_k:][::-1]
        # for node_id in top_k:
        #     human_string = node_lookup.id_to_string(node_id)
        #     score = predictions[node_id]
        #     if score > self.score_threshold:
        #         rospy.loginfo('%s (score = %.5f)' % (human_string, score))
        #         self._pub.publish(human_string)
        # read points from pointcloud message `data`
        clock = Clock()
        rospy.logwarn(
            "subscribed. width: %d, height: %u, point_step: %d, row_step: %d",
            cloud_msg.width, cloud_msg.height, cloud_msg.point_step,
            cloud_msg.row_step)

        pc = pc2.read_points(cloud_msg,
                             skip_nans=False,
                             field_names=("x", "y", "z", "intensity"))
        # to conver pc into numpy.ndarray format
        np_p = np.array(list(pc))
        # perform fov filter by using hv_in_range
        cond = self.hv_in_range(x=np_p[:, 0],
                                y=np_p[:, 1],
                                z=np_p[:, 2],
                                fov=[-45, 45])
        # to rotate points according to calibrated points with velo2cam
        # np_p_ranged = np.stack((np_p[:,1],-np_p[:,2],np_p[:,0],np_p[:,3])).T
        np_p_ranged = np_p[cond]

        # get depth map
        lidar = self.pto_depth_map(velo_points=np_p_ranged, C=5)
        lidar_f = lidar.astype(np.float32)
        #normalize intensity from [0,255] to [0,1], as shown in KITTI dataset
        #dep_map[:,:,0] = (dep_map[:,:,0]-0)/np.max(dep_map[:,:,0])
        #dep_map = cv2.resize(src=dep_map,dsize=(512,64))

        # to perform prediction
        lidar_mask = np.reshape(
            (lidar[:, :, 4] > 0),
            [self._mc.ZENITH_LEVEL, self._mc.AZIMUTH_LEVEL, 1])
        lidar_f = (lidar_f - self._mc.INPUT_MEAN) / self._mc.INPUT_STD
        pred_cls = self._session.run(self._model.pred_cls,
                                     feed_dict={
                                         self._model.lidar_input: [lidar_f],
                                         self._model.keep_prob: 1.0,
                                         self._model.lidar_mask: [lidar_mask]
                                     })
        label = pred_cls[0]
        print(label)
        # # generated depth map from LiDAR data
        depth_map = Image.fromarray(
            (255 * _normalize(lidar[:, :, 3])).astype(np.uint8))
        # # classified depth map with label
        # label_map = Image.fromarray(
        #     (255 * visualize_seg(pred_cls, self._mc)[0]).astype(np.uint8))
        # # blending image: out = image1 * (1.0 - alpha) + image2 * alpha
        # blend_map = Image.blend(
        #     depth_map.convert('RGBA'),
        #     label_map.convert('RGBA'),
        #     alpha=0.4
        # )
        #
        # # save classified depth map image with label
        # blend_map.save(os.path.join(FLAGS.out_dir, 'plot_' + file_name + '.png'))
        label_3d = np.zeros((label.shape[0], label.shape[1], 3))
        label_3d[np.where(label == 0)] = [1., 1., 1.]
        label_3d[np.where(label == 1)] = [0., 1., 0.]
        label_3d[np.where(label == 2)] = [1., 1., 0.]
        label_3d[np.where(label == 3)] = [0., 1., 1.]

        ## point cloud in filed of view
        # x = np_p_ranged[:, 0].reshape(-1)
        # y = np_p_ranged[:, 1].reshape(-1)
        # z = np_p_ranged[:, 2].reshape(-1)
        # i = np_p_ranged[:, 3].reshape(-1)
        ## point cloud for SqueezeSeg segments
        x = lidar[:, :, 0].reshape(-1)
        y = lidar[:, :, 1].reshape(-1)
        z = lidar[:, :, 2].reshape(-1)
        i = lidar[:, :, 3].reshape(-1)
        label = label.reshape(-1)
        # cond = (label!=0)
        # print(cond)
        cloud = np.stack((x, y, z, i, label))
        # cloud = np.stack((x, y, z, i))

        label_map = Image.fromarray(
            (255 * _normalize(label_3d)).astype(np.uint8))

        header = Header()
        header.stamp = rospy.Time()
        header.frame_id = "velodyne"
        # feature map & label map
        msg_feature = ImageConverter.to_ros(depth_map)
        msg_feature.header = header
        msg_label = ImageConverter.to_ros(label_map)
        msg_label.header = header

        # point cloud segments
        # 4 PointFields as channel description
        # msg_segment = pc2.create_cloud(header=header,
        #                                fields=_make_point_field(cloud.shape[0]),
        #                                points=cloud.T)

        # self._feature_map_pub.publish(msg_feature)
        # self._label_map_pub.publish(msg_label)
        # self._pub.publish(msg_segment)

        # save the data
        file_name = "test"

        # generated depth map from LiDAR data
        depth_map = Image.fromarray(
            (255 * _normalize(lidar[:, :, 3])).astype(np.uint8))
        # classified depth map with label
        label_map = Image.fromarray(
            (255 * visualize_seg(pred_cls, self._mc)[0]).astype(np.uint8))
        # blending image: out = image1 * (1.0 - alpha) + image2 * alpha
        blend_map = Image.blend(depth_map.convert('RGBA'),
                                label_map.convert('RGBA'),
                                alpha=0.4)
        # save classified depth map image with label
        blend_map.save(file_name + '.png')

        rospy.loginfo("Point cloud processed. Took %.6f ms.",
                      clock.takeRealTime())
Exemplo n.º 12
0
async def test_simple_start():
    # ensure integrator count and exits work
    c = Clock(100)
    ret = await c.start()
    assert ret == c.default_return
    assert c.integrator == 100
Exemplo n.º 13
0
class Experiment(object):
    """An abstract computational experiment. A set of candidate methods is run on a set of 
    instances and results are extracted and saved."""
    def __init__(self):
        self.log = Logger()
        self.log_block = None
        self.clock = None
        self.params = None
        
    def execute(self, replications=1, **params):
        self.setup(**params)
        self.run(replications)
        self.finalize()
        
    def setup(self, **params):
        self.log.info("Setting up experiment...")
        self.log_block = dict(instance=None, method=None, replication=None)
        self.clock = Clock()
        self.params = Namespace(params)
        self.params.experiment = self
        self.params.log = self.log
        self.on_setup()
        
    def run(self, replications=1):
        self.log.info("Running experiment...")
        self.clock.start()
        self.replications = replications
        for self.instance in self.iter_instances():
            for self.method in self.iter_methods():
                for self.replication in self.iter_replications():
                    self.save_results(self.method(**self.params))
                self.replication = None
            self.method = None
        self.instance = None
        self.clock.stop()
        self.log.info("Experiment completed in %.3f seconds.", self.clock.total)
        
    def finalize(self):
        self.log.info("Finalizing experiment...")
        self.on_finalize()
        
    # --------------------------------------------------------------------------
    # Methods that **must** be defined in subclasses
    # --------------------------------------------------------------------------
    def on_setup(self):
        raise NotImplementedError()
        
    def on_finalize(self):
        raise NotImplementedError()
        
    def iter_instances(self):
        raise NotImplementedError()
        
    def iter_methods(self):
        raise NotImplementedError()
        
    def iter_replications(self):
        return xrange(self.replications)
        
    def save_results(self, results):
        raise NotImplementedError()
        
    # --------------------------------------------------------------------------
    # Auxiliary methods (mainly useful for logging)
    # --------------------------------------------------------------------------
    @property
    def instance(self):
        return self.params.instance
        
    @instance.setter
    def instance(self, instance):
        self.params.instance = instance
        self.set_log_block("instance", instance)
        
    @property
    def method(self):
        return self.params.method
        
    @method.setter
    def method(self, method):
        self.params.method = method
        self.set_log_block("method", method)
        
    @property
    def replication(self):
        return self.params.replication
        
    @replication.setter
    def replication(self, replication):
        self.params.replication = replication
        message = None if replication is None else ("Replication %s" % replication)
        self.set_log_block("replication", message)
        
    @property
    def replications(self):
        return self.params.replications
        
    @replications.setter
    def replications(self, replications):
        self.params.replications = replications
        
    def set_log_block(self, key, value):
        if self.log_block[key] is not None:
            self.log_block[key].exit()
            self.log_block[key] = None
        if value is not None:
            self.log_block[key] = self.log.info.block(value)
            self.log_block[key].enter()
Exemplo n.º 14
0
    def solve(user : User, id_challenge):
        """
        Runs an attempt of user to solve the challenge

        Args:
            user (User): User
            id_challenge (int): ID of Challenge
        """
        challenge = ChallengeCypher.APP.getDBController().getCypherChallenge(id_challenge)
        if challenge is None:
            crt.writeError("This challenge does not exist.")
            crt.pause()
            return
        
        crt.writeMessage(f"Submitted by: {challenge['username']}")
        crt.writeMessage(f"Algorithm:    {challenge['algorithm']}")
        crt.writeMessage(f"Crypto:       {challenge['answer']}")
        crt.writeMessage(f"Plaintext:    {challenge['plaintext']}")
        crt.writeMessage(f"Tip:          {challenge['tip']}")
        crt.newLine()

        id_user = user.getUserID()

        last_try  = ChallengeCypher.APP.getDBController().getCypherLastTry(id_user, id_challenge)
        curr_time = Clock.now()
        if not (last_try is None or Clock.isAfter(curr_time, Clock.addSeconds(last_try, 15))):
            crt.writeWarning("Too soon to try again.")
            crt.pause()
            return None

        challenge['plaintext'] = Padding.appendPadding(challenge['plaintext'], blocksize=Padding.AES_blocksize, mode=0)

        if challenge['algorithm'] == Cypher.Caesar.TYPE:
            proposal_caesar = Read.tryAsInt("Insert your answer (number): ")
            proposal = str(proposal_caesar)
        else:
            proposal = Read.asString("Insert your answer: ")
        
        key      = hashlib.md5(proposal.encode()).digest()
        iv       = challenge['iv']
        hmacdb   = challenge['hmac']
        hmackey  = ChallengeCypher.APP.getDBController().getHMACKey()

        if challenge['algorithm'] == Cypher.ECB.TYPE:
            plaintext = Cypher.ECB.decrypt(base64.b64decode(challenge['answer']), key, AES.MODE_ECB)
        
        elif challenge['algorithm'] == Cypher.CBC.TYPE:
            plaintext = Cypher.CBC.decrypt(base64.b64decode(challenge['answer']), key, AES.MODE_CBC, iv.encode())
        
        elif challenge['algorithm'] == Cypher.CTR.TYPE:
            plaintext = Cypher.CTR.decrypt(base64.b64decode(challenge['answer']), key, AES.MODE_CTR, iv.encode())
        
        elif challenge['algorithm'] == Cypher.Caesar.TYPE:
            plaintext = Cypher.Caesar.decrypt(base64.b64decode(challenge['answer']), proposal_caesar)
        
        elif challenge['algorithm'] == Cypher.OTP.TYPE:
            plaintext = Cypher.OTP.decrypt(base64.b64decode(challenge['answer']), proposal)
        
        elif challenge['algorithm'] == Cypher.Vigenere.TYPE:
            plaintext = Cypher.Vigenere.decrypt(base64.b64decode(challenge['answer']), proposal).lower()
        
        try:
            plaintext = Padding.removePadding(plaintext.decode(),mode=0)
        except:
            ()
        msgHMAC = hmac.new(hmackey, plaintext.encode(), hashlib.sha256)

        # crt.writeDebug(f"{msgHMAC.hexdigest()} == {hmacdb}")
        if (msgHMAC.hexdigest() == hmacdb):
            if ChallengeCypher.APP.getDBController().updateCypherChallengeTry(id_user, id_challenge, Clock.now(), True):
                crt.writeSuccess("YOU DID IT!")
            else:
                crt.writeError("You got it, but I could not save the answer.")
        else:
            if ChallengeCypher.APP.getDBController().updateCypherChallengeTry(id_user, id_challenge, Clock.now(), False):
                crt.writeMessage("Better luck next time :(")
            else:
                crt.writeError("You did NOT got it, but I could not save the answer.")
        crt.pause()
Exemplo n.º 15
0
    def npy2cloud(self, is_ground_truth, npy_dir):
        """

        :param cloud_msg:
        :return:
        """
        if is_ground_truth:
            rospy.loginfo("SHOW GROUND TRUTH LABEL !")
        else:
            rospy.loginfo("SHOW PREDICTED LABEL !")

        files_list = os.listdir(npy_dir)
        files_list.sort()
        count = 0
        while not rospy.is_shutdown() and count < len(files_list):
            clock = Clock()
            npy_file = files_list[count]

            points = np.load(os.path.join(npy_dir, npy_file))
            lidar = points[:, :, :5]
            lidar_f = lidar.astype(np.float32)
            #normalize intensity from [0,255] to [0,1], as shown in KITTI dataset
            #dep_map[:,:,0] = (dep_map[:,:,0]-0)/np.max(dep_map[:,:,0])
            #dep_map = cv2.resize(src=dep_map,dsize=(512,64))

            # to perform prediction
            lidar_mask = np.reshape(
                (lidar[:, :, 4] > 0),
                [self._mc.ZENITH_LEVEL, self._mc.AZIMUTH_LEVEL, 1])
            lidar_f = (lidar_f - self._mc.INPUT_MEAN) / self._mc.INPUT_STD
            pred_cls = self._session.run(self._model.pred_cls,
                                         feed_dict={
                                             self._model.lidar_input:
                                             [lidar_f],
                                             self._model.keep_prob: 1.0,
                                             self._model.lidar_mask:
                                             [lidar_mask]
                                         })
            label = pred_cls[0]
            if is_ground_truth:
                label = points[:, :, 5]
            # df = pd.DataFrame(label)
            # print df.size
            # df.to_csv("/home/sang/categray.csv")

            # # generated depth map from LiDAR data
            depth_map = Image.fromarray(
                (255 * _normalize(lidar[:, :, 3])).astype(np.uint8))

            label_3d = np.zeros((label.shape[0], label.shape[1], 3))
            label_3d[np.where(label == 0)] = [1., 1., 1.]
            label_3d[np.where(label == 1)] = [0., 1., 0.]
            label_3d[np.where(label == 2)] = [1., 1., 0.]
            label_3d[np.where(label == 3)] = [0., 1., 1.]

            x = lidar[:, :, 0].reshape(-1)
            y = lidar[:, :, 1].reshape(-1)
            z = lidar[:, :, 2].reshape(-1)
            i = lidar[:, :, 3].reshape(-1)
            label = label.reshape(-1)
            # print len(label)
            # cond = (label!=0)
            # print(cond)
            cloud = np.stack((x, y, z, i, label))
            print len(cloud.T)
            # cloud = np.stack((x, y, z, i))

            label_map = Image.fromarray(
                (255 * _normalize(label_3d)).astype(np.uint8))

            header = Header()
            header.stamp = rospy.Time()
            header.frame_id = "velodyne"
            # feature map & label map
            msg_feature = ImageConverter.to_ros(depth_map)
            msg_feature.header = header
            msg_label = ImageConverter.to_ros(label_map)
            msg_label.header = header

            # point cloud segments
            # 4 PointFields as channel description
            msg_segment = pc2.create_cloud(header=header,
                                           fields=_make_point_field(
                                               cloud.shape[0]),
                                           points=cloud.T)

            self._feature_map_pub.publish(msg_feature)
            self._label_map_pub.publish(msg_label)
            self._pub.publish(msg_segment)
            rospy.loginfo("Point cloud %d processed. Took %.6f ms.", count,
                          clock.takeRealTime())
            count = count + 1
Exemplo n.º 16
0
    def point_cloud_callback(self, cloud_msg):
        """

        :param cloud_msg:
        :return:
        """
        clock = Clock()
        # rospy.logwarn("subscribed. width: %d, height: %u, point_step: %d, row_step: %d",
        #               cloud_msg.width, cloud_msg.height, cloud_msg.point_step, cloud_msg.row_step)

        pc = pc2.read_points(cloud_msg, skip_nans=False, field_names=("x", "y", "z","intensity","d"))
        # to conver pc into numpy.ndarray format
        np_p = np.array(list(pc))

        # print("shape : {}".format(np_p.shape))

        # get depth map
        lidar = np_p.reshape(64,512,5)

        # print("{}".format(lidar.shape))

        lidar_f = lidar.astype(np.float32)

        # to perform prediction
        lidar_mask = np.reshape(
            (lidar[:, :, 4] > 0),
            [self._mc.ZENITH_LEVEL, self._mc.AZIMUTH_LEVEL, 1]
        )
        lidar_f = (lidar_f - self._mc.INPUT_MEAN) / self._mc.INPUT_STD
        pred_cls = self._session.run(
            self._model.pred_cls,
            feed_dict={
                self._model.lidar_input: [lidar_f],
                self._model.keep_prob: 1.0,
                self._model.lidar_mask: [lidar_mask]
            }
        )
        label = pred_cls[0]

        ## point cloud for SqueezeSeg segments
        x = lidar[:, :, 0].reshape(-1)
        y = lidar[:, :, 1].reshape(-1)
        z = lidar[:, :, 2].reshape(-1)
        i = lidar[:, :, 3].reshape(-1)
        label = label.reshape(-1)
        cloud = np.stack((x, y, z, i, label))


        header = Header()
        header.stamp = rospy.Time()
        header.frame_id = "velodyne_link"

        # point cloud segments
        # 4 PointFields as channel description
        msg_segment = pc2.create_cloud(header=header,
                                       fields=_make_point_field(cloud.shape[0]),
                                       points=cloud.T)

        # ed: /squeeze_seg/points publish
        self._pub.publish(msg_segment)
        rospy.loginfo("Point cloud processed. Took %.6f ms.", clock.takeRealTime())
Exemplo n.º 17
0
from utils.clock import Clock
from utils.drawer import Drawer
from utils.videoStream import VideoStream
from utils.box_choose import box_choose, choose

from det2.det2 import Det2
from norfair import Detection, Tracker, draw_tracked_objects

parser = argparse.ArgumentParser()
parser.add_argument("--nodisplay", action="store_true")
parser.add_argument("--time",
                    help="flag to switch on timing",
                    action="store_true")
args = parser.parse_args()

clock = Clock()

video_path = env.get('VIDEO_FEED', 0)
video_name = env.get('VIDEO_NAME', 'cam')
is_webcam = bool(int(env.get('VIDEO_IS_USB_WEBCAM', 1)))
if is_webcam:
    video_path = int(video_path)
flip = bool(int(env.get('VIDEO_FLIP', 0)))
if flip:
    print('VIDEO WILL FLIP')
else:
    print('VIDEO WILL NOT FLIP')
video_store_raw = bool(int(env.get('VIDEO_STORE_RAW', 0)))

# print ("Video Path: {}".format(video_path))
# stream = VideoStream(video_name, video_path, clock=clock, store_raw=video_store_raw, queueSize=5)