Beispiel #1
0
def main():
    app = QtWidgets.QApplication(sys.argv)
    udp = UdpThread()
    udp.connect()
    udp.start()
    Graph(rssi_listener=udp).show()
    sys.exit(app.exec_())
Beispiel #2
0
    def _generate_graph_embeddings(self):
        '''
        This function first generates an object tree using the ObjectTree Class
        and then generates a graph using the Graph Class. 

        The output of this function is a feature array along with label array
        (if any).
        '''
        self.tree = ObjectTree()
        self.graph = Graph()

        # Generate a graph dictionary
        self.tree.read(self.object_map, self.image)
        graph_dict, text_list, coords_arr = self.tree.connect(plot=False,
                                                              export_df=True)

        # Generate the Adjacency Matrix (A) and the Feature Matrix (X)
        A, X = self.graph.make_graph_data(graph_dict=graph_dict,
                                          text_list=text_list,
                                          coords_arr=coords_arr,
                                          img_dims=self.img_dims)

        # transform the feature matrix by muptiplying with the Adjacency Matrix
        X_transformed = np.matmul(A, X)

        # form new feature matrix
        self.X = np.concatenate((X, X_transformed), axis=1)
    def appStarted(mode):
        try:
            mode.bg = mode.loadImage("muslevelbg.jpg")
        except:
            mode.bg = mode.loadImage("https://i.ibb.co/8DwvThD/muslevelbg.jpg")
        mode.Progress = Progress()
        mode.gameState = "levels"
        mode.game = "music"
        (mode.marginX, mode.marginY) = (mode.app.width // 10,
                                        mode.app.height // 9)
        (mode.puzzleW, mode.puzzleH) = (mode.app.width - 2 * mode.marginX,
                                        mode.app.height - 2 * mode.marginY)
        mode.widthUnit = mode.app.width // 10
        mode.heightUnit = mode.app.height // 9
        mode.selected = [(-100, -100)]
        mode.complete = False

        mode.lastBeatTimer = 0
        mode.beatTimer = 0

        mode.dots = []
        mode.createButtons()
        mode.levelButtons = []
        levelPageB = FakeButton(mode.widthUnit * 0.5, mode.heightUnit * 5.5,
                                mode.widthUnit * 0.8, mode.heightUnit * 0.6,
                                "Levels", mode.levelPageBCom, mode)
        mode.buttons.append(levelPageB)
        cusLevelB = FakeButton(mode.widthUnit * 0.5, mode.heightUnit * 1.5,
                               mode.widthUnit * 0.8, mode.heightUnit * 0.6,
                               " S ", mode.cusBCom, mode, " S ")
        level1B = FakeButton(mode.widthUnit * 1.5, mode.heightUnit * 1.5,
                             mode.widthUnit * 0.8, mode.heightUnit * 0.6,
                             " 1 ", mode.levelBCom, mode, " 1 ")
        mode.levelButtons.append(cusLevelB)
        mode.levelButtons.append(level1B)

        mode.fourierColors = "#FFC5C5"
        mode.fourierGraph = Graph((mode.app.width, 0), mode.app.height,
                                  mode.fourierColors, 1.5,
                                  0.684 * MusicGameMode.fourierInterval, False)

        mode.colorschemas = [
            ["#55efc4", "#81ecec", "#74b9ff", "#a29bfe", "#ffeaa7", "#fab1a0"],
            ["#fa983a", "#b71540", "#F8EFBA", "#1e3799", "#3c6382"],
            ["#00CCCD", "#1287A5", "#EA7773", "#2B2B52", "#F5BCBA"],
            ["#30336B", "#67E6DC", "#0A3D62", "#6A89CC"],
            ["#40407a", "#706fd3", "#f7f1e3", "#34ace0", "#33d9b2"]
        ]
        mode.colors = mode.colorschemas[0]
        mode.time = 0
        mode.last = 0

        mode.backgroundColor = "#FEFEFE"
        mode.font = "Calibri"

        mode.velx = 10
        mode.vely = 10
        mode.offset = 0
        mode.lastBeat = int(round(time.time() * 1000))
Beispiel #4
0
        json_file = name + str(i).zfill(5) + '.json'
        image_file = name + str(i).zfill(5) + '.png'
        receipt_csv_file = name + str(i).zfill(5) + '.csv'
        print(json_file, image_file, receipt_csv_file)

        receipt_csv = pd.read_csv(folderNameReceipt_csv + receipt_csv_file)
        img = cv2.imread(folderName_image + image_file, 0)

        # json_path = '/home/arjun/Gcn_paper/gcn/gcn/OneDrive_2020-11-13/spaCy NER Annotator output/Image_0006.json'
        tree = ObjectTree()
        tree.read(receipt_csv, img)

        graph_dict, text_list = tree.connect(plot=True, export_df=True)

        graph = Graph(max_nodes=len(text_list))

        adj, features = graph.make_graph_data(graph_dict, text_list)
        adj = sparse.csr_matrix(adj)
        adj = normalize(adj + sp.eye(adj.shape[0]))

        # adj = sparse_mx_to_torch_sparse_tensor(adj)
        if first_count == 0:
            features_merged = features
        else:
            features_merged = np.concatenate((features_merged, features),
                                             axis=0)

        # features = sparse.csr_matrix(features)
        # features = torch.FloatTensor(np.array(features.todense()))
        adj_array.append(adj.todense())
Beispiel #5
0
def init(data):  #Initialize all of data's variables
    global dati
    dati = data

    data.checkRadius = 400
    data.targetRadii = []
    data.leftScore = 0
    data.rightScore = 0
    data.leftDistance = 99999
    data.rightDistance = 99999
    data.lastBeatTimer = 0
    data.beatTimer = 0
    data.circWidth = 3
    data.circColor = "black"

    data.songPath = ""
    data.dots = []
    data.buttons = []
    data.instant_energies = []
    data.energy_averages = []
    data.maxEnergy = 0
    data.beats = []
    data.fourier = []
    data.fourier_colors = ["#FFC5C5", "#FFDFDF"]
    data.colorschemas = [
        ["#BE1B38", "#01A98F", "#C9CF7E", "#E86644"],
        ["#354458", "#EB7260", "#29ABA4", "#E9E0D6", "#3A9AD9"],
        ["#FF0066", "#333366", "#3399CC", "#00CCCC", "#003399"],
        ["#a6dace", "#F7A04B", "#666699", "#EF8D24"],
        ["#05b3b2", "#2ca5dc", "#a5d3ea", "#f4cfbd", "#ff946c"]
    ]
    data.colors = data.colorschemas[0]
    data.targets = []
    data.time = 0
    data.last = 0
    data.radius = 10
    data.posx = data.width // 3
    data.posy = data.height // 2
    pickNewTarget(data)
    data.timescale = 1.0
    data.backgroundBase = "#FEFEFE"
    data.font = "Calibri"
    data.gamestate = 0
    data.gamemode = "song"
    data.offset = 0
    data.score = 0
    data.graphers = []
    data.lastBeat = int(round(time.time() * 1000))
    data.lastCallBack = time.time()
    data.backgroundColor = data.backgroundBase
    data.canvas = None
    data.playerPhased = False
    data.soundcloudActive = False
    data.beats = []

    data.velx = 10
    data.vely = 10
    data.p = None
    data.volSum = 1841616
    data.volCount = 1
    data.max = 343

    data.phaseJuice = 0
    data.maxPhaseJuice = 100
    data.boostJuice = 0
    data.maxBoostJuice = 100

    data.playerR = 370
    data.playerPos = 6.28
    data.playerVel = 0
    data.playerAcel = 0.001

    data.graphers += [BeatGrapher((1390, 10), 250, "#979797")]
    data.graphers += [Graph((1390, 10), 250, "red")]
    data.graphers += [Graph((1390, 10), 250, "green", 1)]
    data.graphers += [Graph((1390, 10), 250, "blue", 2)]
    data.graphers += [
        Graph((1412, 260), 300, data.fourier_colors[0], 1.5,
              0.684 * fourierInterval, False)
    ]
    # Usual Fourier height = 625

    makeBtns(data)
Beispiel #6
0
def keyPressed(event, data):
    if (event.keysym == "space"):  #Slow down time (or speed it back up)
        if (data.timescale == 1):
            data.backup = data.colors
            data.timescale = 0.2
            for dot in data.dots:
                dot.fill = "#FF0051"
            data.colors = ["#FF0051"]
            data.backgroundColor = "#FFB9B9"
            data.graphers[4] = Graph((1412, 260), 300, data.fourier_colors[1],
                                     1.5, 0.684 * fourierInterval,
                                     False)  #Change the fourier graph's colors
            if (data.gamemode == "song"):
                remakeStream(songTimeScale)
        else:
            proont("-----")
            data.timescale = 1.0
            data.backgroundColor = data.backgroundBase
            data.colors = data.backup
            for dot in data.dots:
                dot.fill = random.choice(data.colors)
            data.graphers[4] = Graph((1412, 260), 300, data.fourier_colors[0],
                                     1.5, 0.684 * fourierInterval,
                                     False)  #Change the fourier graph's colors
            if (data.gamemode == "song"):
                remakeStream(1)

    elif (event.keysym == "r"):  #Move the emitter back to the center
        data.posx = data.width // 2
        data.posy = data.height // 2
        data.startx = data.posx
        data.starty = data.posy

    #Change some game modes
    elif (event.keysym == "1"):
        data.gamestate = 1
        data.timer = 0
    elif (event.keysym == "2"):
        data.gamestate = 2
        data.startx = data.posx
        data.starty = data.posy
    elif (event.keysym == "3"):
        data.gamestate = 3
        data.startx = data.posx
        data.starty = data.posy
    elif (event.keysym == "4"):
        data.gamestate = 4
    elif (event.keysym == "5"):
        data.gamestate = 5

    elif (event.keysym == "Escape"):  #Go back to the menu screen and clean up
        data.gamestate = 0
        if (data.stream != None):
            data.stream.stop_stream()
        data.p = None
        data.stream = None
        data.maxEnergy = 0
        data.timescale = 1
        data.gamemode = "song"
        data.fourier = []
        data.instant_energies = []
        data.energy_averages = []
        data.beats = []
        data.graphers[4].maxVal = 0
        data.playerR = 370
        data.playerPos = 6.28
        data.playerVel = 0
        data.leftScore = 0
        data.rightScore = 0
        data.targetRadii = []

    elif (event.keysym == "0"):  #Change the emitter's colors
        changeColors(data)

    if (not data.gamemode == "sandbox"
        ):  #If we're playing a game, handle the players' key presses
        if (event.keysym == "a"):
            bestDist = 9999999
            for test in data.targetRadii:
                distance = abs(data.checkRadius - test)
                if distance < bestDist:
                    bestDist = distance
            data.leftDistance = bestDist
            if (bestDist > 50
                ):  #If there's no beat even somewhat close, they lose points
                data.leftScore -= 1
            else:
                data.beatTimer = 2  #Wait a bit for the other player to make their move before we decide who gets the beat

        elif (event.keysym == "l"):
            bestDist = 9999999
            for test in data.targetRadii:
                distance = abs(data.checkRadius - test)
                if distance < bestDist:
                    bestDist = distance
            data.rightDistance = bestDist
            if (bestDist > 50
                ):  #If there's no beat even somewhat close, they lose points
                data.rightScore -= 1
            else:
                data.beatTimer = 2  #Wait a bit for the other player to make their move before we decide who gets it

    pass
Beispiel #7
0
def get_train_data(data_folder_path):
    # ============= get paths for images and object maps ===========================
    image_jpg_path_glob = data_folder_path + r'\*\*.jpg'
    image_png_path_glob = data_folder_path + r'\*\*.png'
    csv_path_glob = data_folder_path + r'\*\*.csv'

    list_img_paths = glob(image_jpg_path_glob) + \
        glob(image_png_path_glob)
    list_csv_paths = glob(csv_path_glob)
    # ------------------------------------------------------------------------------

    # =============== initialize the ObjectTree and Graph Objects ==================
    tree = ObjectTree()
    graph = Graph()
    # ------------------------------------------------------------------------------

    # === generate graph embeddings for each document ==============================
    data_df = pd.DataFrame(columns=['features', 'label'])
    count, skip_count = 0, 0

    for image_path, csv_path in zip(list_img_paths, list_csv_paths):

        img = cv2.imread(image_path, 0)
        object_map = pd.read_csv(csv_path)

        # drop rows with nans
        object_map.dropna(inplace=True, how='any')

        try:
            # generate object tree
            tree.read(object_map, img)
            graph_dict, text_list, coords_arr = tree.connect(plot=True,
                                                             export_df=True)

            # make graph data
            A, X = graph.make_graph_data(graph_dict, text_list, coords_arr,
                                         img)

            # transform the feature matrix by muptiplying with the Adjacency Matrix
            X_transformed = np.matmul(A, X)

            # form new feature matrix
            X = np.concatenate((X, X_transformed), axis=1)

            # get the labels
            y = object_map.label.values

            if count == 0:
                X_train = X
                y_train = y

            else:
                X_train = np.concatenate((X_train, X), axis=0)
                y_train = np.concatenate((y_train, y), axis=0)

            print('Finished processing image {} of {}...'.format(
                count, len(list_img_paths)))

        except Exception:
            skip_count += 1
            print('Skipping Graph Generation...')

        count += 1



    print('Finished generating Graph Dataset for {} documents. Skipped {}.'\
        .format(count, skip_count))

    return X_train, y_train