def rotate_file(fileName):
    js = json.loads(open(fileName).read())
    for items in js['people']:
        handRight = items["hand_right_keypoints_2d"]
    
    handPoints = helper.removePoints(handRight)
    
    
    
    p1 = [handPoints[0], handPoints[1]]
    p2 = [handPoints[18], handPoints[19]]
    distance = math.sqrt( ((p1[0]-p2[0])**2)+((p1[1]-p2[1])**2) )
    
    Result,Points = scale.scalePoints(handPoints,distance)
       
    handRightResults,handRightPoints = move.centerPoints(Result) 
    
    newPoints = [handRightPoints[0]]
    for x in range(1,len(handRightPoints)):
        newPoints.append( rotate(handRightPoints[x],-60,handRightPoints[0]) )
    
    newPoints = helper.seperate_points(newPoints)
    return newPoints
def match_ann(fileName):
    js = json.loads(open(fileName).read())
    for items in js['people']:
        pose = items["pose_keypoints_2d"]
        handRight = items["hand_right_keypoints_2d"]
        handLeft = items["hand_left_keypoints_2d"]

    RightConfPoints = helper.confidencePoints(handRight)
    LeftConfPoints = helper.confidencePoints(handLeft)

    # add all confidence points
    RightConfidence = helper.confidence(RightConfPoints)
    LeftConfidence = helper.confidence(LeftConfPoints)

    # remove file if confidence is less than threshold
    if RightConfidence > 12:
        if LeftConfidence > 12 or LeftConfidence < 2:

            # normalizing bodyKeyPoints
            pose_points = helper.removePoints(pose)
            p1 = [pose_points[0], pose_points[1]]
            p2 = [pose_points[2], pose_points[3]]
            distance = math.sqrt(((p1[0] - p2[0])**2) + ((p1[1] - p2[1])**2))
            scaled_results, scaled_points = norm.scaleBody(
                pose_points, distance)
            poseResults, posePoints = norm.moveBody(scaled_results)

            # normalizing RightHandKeyPoints
            hand_right_points = helper.removePoints(handRight)
            p1 = [hand_right_points[0], hand_right_points[1]]
            p2 = [hand_right_points[18], hand_right_points[19]]
            distance = math.sqrt(((p1[0] - p2[0])**2) + ((p1[1] - p2[1])**2))
            RightResult, Points = scale.scalePoints(hand_right_points,
                                                    distance)
            handRightResults, handRightPoints = norm.move_to_wrist(
                RightResult, poseResults[8], poseResults[9])

            # normalizing LeftHandKeyPoints
            if LeftConfidence > 3:
                hand_left_points = helper.removePoints(handLeft)
                p1 = [hand_left_points[0], hand_left_points[1]]
                p2 = [hand_left_points[18], hand_left_points[19]]
                distance = math.sqrt(((p1[0] - p2[0])**2) +
                                     ((p1[1] - p2[1])**2))
                if distance != 0:
                    LeftResult, Points = scale.scalePoints(
                        hand_left_points, distance)
                    handLeftResults, handLeftPoints = norm.move_to_wrist(
                        LeftResult, poseResults[14], poseResults[15])
                else:
                    handLeftResults, handLeftPoints = norm.move_to_wrist(
                        hand_left_points, poseResults[14], poseResults[15])

            else:
                handLeftResults = [
                    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                    0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                    0.0, 0.0, 0.0, 0.0, 0.0, 0.0
                ]

            # combining points
            posePoints = []
            for x in range(18):
                posePoints.append(poseResults[x])
            for x in range(30, 38):
                posePoints.append(poseResults[x])

            results = handRightResults + handLeftResults + posePoints

            # extracting data from db
            connection = sqlite3.connect("data\\db\\main_dataset.db")
            crsr = connection.cursor()

            # extracting x and y points
            sql = 'SELECT Rx1,Ry1'
            for x in range(2, 22):
                sql = sql + ',Rx' + str(x) + ',Ry' + str(x)
            for x in range(1, 22):
                sql = sql + ',Lx' + str(x) + ',Ly' + str(x)
            for x in range(1, 14):
                sql = sql + ',Px' + str(x) + ',Py' + str(x)
            sql = sql + ' FROM poseDataset WHERE 1'
            crsr.execute(sql)
            feature_res = crsr.fetchall()
            feature_res = np.asarray(feature_res)
            features = []
            for x in feature_res:
                features.append(x)

            # extracting labels
            crsr.execute('SELECT label FROM poseDataset WHERE 1')
            label_res = crsr.fetchall()
            labels = []
            for x in label_res:
                labels.append(x)

            # Creating labelEncoder
            le = preprocessing.LabelEncoder()

            # Converting string labels into numbers.
            label_encoded = le.fit_transform(labels)

            label_encoded = to_categorical(label_encoded)

            X_train, X_test, y_train, y_test = train_test_split(features,
                                                                label_encoded,
                                                                test_size=0.2)

            scaler = StandardScaler().fit(X_train)
            X_train = scaler.transform(X_train)
            X_test = scaler.transform(X_test)

            y_pred = model.predict(scaler.transform(np.array([results])))

            C = np.argmax(y_pred)

            result = le.inverse_transform([C])

            return result[0]
        else:
            return "no confidence"
    else:
        return "no confidence"
def match(speech, mode):
    global label, lastLabel
    """
    Load each .json file from Keypoints folder and
    predict the label
    """

    for entry in os.scandir('Keypoints'):
        if entry.is_file():
            if os.path.splitext(entry)[1] == ".json":
                filePlotName = entry.name

    try:
        js = json.loads(open('Keypoints\\' + filePlotName).read())
        # extract 'hand_right_keypoints_2d' from json file
        for items in js['people']:
            pose = items["pose_keypoints_2d"]
            handRight = items["hand_right_keypoints_2d"]
            handLeft = items["hand_left_keypoints_2d"]

        pose_points = helper.removePoints(pose)
        posePoints = helper.join_points(pose_points)

        #  function to remove confidence points
        hand_right_Points = helper.removePoints(handRight)
        handRightPoints = helper.join_points(hand_right_Points)

        hand_left_points = helper.removePoints(handLeft)
        handLeftPoints = helper.join_points(hand_left_points)

        frame = plotPose(posePoints, handRightPoints, handLeftPoints)

        #    if hand_right_Points[0] != 0:
        cv2.imwrite('gui\\Learn_images\\' + filePlotName + '.jpg', frame)
        # reset image
        frame = cv2.imread("PSL\\BLACK_background.jpg")
        eel.get_fileName(filePlotName)
    except:
        print('Decoding JSON has failed')
        pass

    try:
        if mode == 0:
            label = alphabet.match_ann('Keypoints\\' + filePlotName)

        if mode == 1:
            label = word.match_ann('Keypoints\\' + filePlotName)
            print(label)
    except Exception:
        pass

    if label != 'no match' and label != 'no confidence' and label != lastLabel:
        lastLabel = label
        if speech == 1:
            try:
                mp3 = "data\\speech\\" + label + ".mp3"
                mixer.init()
                mixer.music.load(mp3)
                mixer.music.play()
            except:
                pass
        return label
def learning():
    global skip_sign
    """
    storing json files to temporary folder [Keypoints]
    Creating temp folder and initializing with zero padded json file
    """

    dirName = 'Keypoints'
    fileName = 'PSL\\000000000000_keypoints.json'

    try:
        # Create target Directory
        os.mkdir(dirName)
        shutil.copy(fileName, dirName)
        print("Directory ", dirName, " Created ")
    except FileExistsError:
        print("Directory ", dirName, " already exists")

    label = ''
    for x in range(len(fileNames)):

        skip_sign = False
        eel.get_Alphabet(x + 1)

        while label != labels[x]:

            for entry in os.scandir('Keypoints'):
                if entry.is_file():
                    if os.path.splitext(entry)[1] == ".json":
                        filePlotName = entry.name

            try:
                js = json.loads(open('Keypoints\\' + filePlotName).read())
            except ValueError:
                print('Decoding JSON has failed')
                pass

            # extract 'hand_right_keypoints_2d' from json file
            for items in js['people']:
                pose = items["pose_keypoints_2d"]
                handRight = items["hand_right_keypoints_2d"]
                handLeft = items["hand_left_keypoints_2d"]

            pose_points = helper.removePoints(pose)
            posePoints = helper.join_points(pose_points)

            #  function to remove confidence points
            hand_right_Points = helper.removePoints(handRight)
            handRightPoints = helper.join_points(hand_right_Points)

            hand_left_points = helper.removePoints(handLeft)
            handLeftPoints = helper.join_points(hand_left_points)

            frame = plotPose(posePoints, handRightPoints, handLeftPoints)

            if hand_right_Points[0] != 0:
                cv2.imwrite('gui\\Learn_images\\' + filePlotName + '.jpg',
                            frame)
                #reset image
                frame = cv2.imread("PSL\\BLACK_background.jpg")
                eel.get_fileName(filePlotName)

            eel.sleep(0.05)

            if skip_sign == True:
                break
            try:

                for entry in os.scandir('Keypoints'):
                    if entry.is_file():
                        if os.path.splitext(entry)[1] == ".json":
                            fileName = entry.name

                try:
                    label = alphabet.match_ann('Keypoints\\' + fileName)
                except:
                    pass

            except UnboundLocalError:
                print("UnboundLocalError")

        eel.get_status()
        print("end while")

    return True
def populate_db():
    """
    Delete all records from database
    """
    connection = sqlite3.connect("data\\db\\main_dataset.db")
    crsr = connection.cursor()
    sql_command = "DELETE FROM rightHandDataset;"
    crsr.execute(sql_command)
    connection.commit()
    connection.close()

    folders = []
    files = []
    fileNames = []

    for entry in os.scandir('data\\datasets\\alphabets_dataset'):
        if entry.is_dir():
            folders.append(entry.path)
            for entry1 in os.scandir(entry.path):
                if entry1.is_dir():
                    folders.append(entry1.path)
                    for entry2 in os.scandir(entry1.path):
                        if entry2.is_dir():
                            folders.append(entry2.path)
                        elif entry2.is_file():
                            if os.path.splitext(entry2)[1] == ".json":
                                files.append(entry2.path)
                                fileNames.append(entry2.name)
                elif entry1.is_file():
                    if os.path.splitext(entry1)[1] == ".json":
                        files.append(entry1.path)
                        fileNames.append(entry1.name)
        elif entry.is_file():
            if os.path.splitext(entry)[1] == ".json":
                fileNames.append(entry1.name)

    # connecting to the database
    connection = sqlite3.connect("data\\db\\main_dataset.db")
    # cursor
    crsr = connection.cursor()

    count = 0

    for file in files:
        js = json.loads(open(files[count]).read())

        parent = (os.path.dirname(files[count])).split('\\')

        parentName = "'" + parent[len(parent) - 2] + "'"

        count += 1
        for items in js['people']:
            handRight = items["hand_right_keypoints_2d"]

        handPoints = helper.removePoints(handRight)
        p1 = [handPoints[0], handPoints[1]]
        p2 = [handPoints[18], handPoints[19]]
        distance = math.sqrt(((p1[0] - p2[0])**2) + ((p1[1] - p2[1])**2))

        Result, Points = scale.scalePoints(handPoints, distance)

        handRightResults, handRightPoints = move.centerPoints(Result)

        # SQL command to insert the data in the table
        sql_command = "INSERT INTO rightHandDataset VALUES (NULL, " + str(
            handRightResults[0]) + ", " + str(handRightResults[1]) + "," + str(
                handRightResults[2]
            ) + "," + str(handRightResults[3]) + "," + str(
                handRightResults[4]
            ) + "," + str(handRightResults[5]) + "," + str(
                handRightResults[6]
            ) + "," + str(handRightResults[7]) + "," + str(
                handRightResults[8]) + "," + str(
                    handRightResults[9]) + "," + str(
                        handRightResults[10]) + "," + str(
                            handRightResults[11]) + "," + str(
                                handRightResults[12]
                            ) + "," + str(handRightResults[13]) + "," + str(
                                handRightResults[14]
                            ) + "," + str(handRightResults[15]) + "," + str(
                                handRightResults[16]
                            ) + "," + str(handRightResults[17]) + "," + str(
                                handRightResults[18]
                            ) + "," + str(handRightResults[19]) + "," + str(
                                handRightResults[20]
                            ) + "," + str(handRightResults[21]) + "," + str(
                                handRightResults[22]
                            ) + "," + str(handRightResults[23]) + "," + str(
                                handRightResults[24]
                            ) + "," + str(handRightResults[25]) + "," + str(
                                handRightResults[26]
                            ) + "," + str(handRightResults[27]) + "," + str(
                                handRightResults[28]
                            ) + "," + str(handRightResults[29]) + "," + str(
                                handRightResults[30]
                            ) + "," + str(handRightResults[31]) + "," + str(
                                handRightResults[32]
                            ) + "," + str(handRightResults[33]) + "," + str(
                                handRightResults[34]
                            ) + "," + str(handRightResults[35]) + "," + str(
                                handRightResults[36]
                            ) + "," + str(handRightResults[37]) + "," + str(
                                handRightResults[38]) + "," + str(
                                    handRightResults[39]) + "," + str(
                                        handRightResults[40]) + "," + str(
                                            handRightResults[41]
                                        ) + "," + parentName + ");"
        crsr.execute(sql_command)

    connection.commit()
    connection.close()
def populate_words():
    """
    Delete all records from database
    """
    connection = sqlite3.connect("data\\db\\main_dataset.db")
    crsr = connection.cursor()
    sql_command = "DELETE FROM poseDataset;"
    crsr.execute(sql_command)
    connection.commit()
    connection.close()

    print("records deleted, new records will be entered now")

    folders = []
    files = []
    fileNames = []

    for entry in os.scandir('data\\datasets\\words_dataset'):
        if entry.is_dir():
            folders.append(entry.path)
            for entry1 in os.scandir(entry.path):
                if entry1.is_dir():
                    folders.append(entry1.path)
                    for entry2 in os.scandir(entry1.path):
                        if entry2.is_dir():
                            folders.append(entry2.path)
                        elif entry2.is_file():
                            if os.path.splitext(entry2)[1] == ".json":
                                files.append(entry2.path)
                                fileNames.append(entry2.name)
                elif entry1.is_file():
                    if os.path.splitext(entry1)[1] == ".json":
                        files.append(entry1.path)
                        fileNames.append(entry1.name)
        elif entry.is_file():
            if os.path.splitext(entry)[1] == ".json":
                fileNames.append(entry1.name)

    # connecting to the database
    connection = sqlite3.connect("data\\db\\main_dataset.db")
    # cursor
    crsr = connection.cursor()

    count = 0

    for file in files:
        js = json.loads(open(files[count]).read())

        parent = (os.path.dirname(files[count])).split('\\')

        parentName = "'" + parent[len(parent) - 2] + "'"

        count += 1
        for items in js['people']:
            pose = items["pose_keypoints_2d"]
            handRight = items["hand_right_keypoints_2d"]
            handLeft = items["hand_left_keypoints_2d"]

        # extract confidence points
        LeftConfPoints = helper.confidencePoints(handLeft)
        # add all confidence points
        LeftConfidence = helper.confidence(LeftConfPoints)

        pose_points = helper.removePoints(pose)
        #posePoints = helper.join_points(pose_points)
        p1 = [pose_points[0], pose_points[1]]
        p2 = [pose_points[2], pose_points[3]]
        distance = math.sqrt(((p1[0] - p2[0])**2) + ((p1[1] - p2[1])**2))
        scaled_results, scaled_points = norm.scaleBody(pose_points, distance)
        poseResults, posePoints = norm.moveBody(scaled_results)

        hand_right_points = helper.removePoints(handRight)
        p1 = [hand_right_points[0], hand_right_points[1]]
        p2 = [hand_right_points[18], hand_right_points[19]]
        distance = math.sqrt(((p1[0] - p2[0])**2) + ((p1[1] - p2[1])**2))
        RightResult, Points = scale.scalePoints(hand_right_points, distance)
        handRightResults, handRightPoints = norm.move_to_wrist(
            RightResult, poseResults[8], poseResults[9])

        if LeftConfidence > 2:
            hand_left_points = helper.removePoints(handLeft)
            p1 = [hand_left_points[0], hand_left_points[1]]
            p2 = [hand_left_points[18], hand_left_points[19]]
            distance = math.sqrt(((p1[0] - p2[0])**2) + ((p1[1] - p2[1])**2))
            LeftResult, Points = scale.scalePoints(hand_left_points, distance)
            handLeftResults, handLeftPoints = norm.move_to_wrist(
                LeftResult, poseResults[14], poseResults[15])
        else:
            handLeftResults = [
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
                0.0,
            ]

        # SQL command to insert the data in the table
        sql_command = "INSERT INTO poseDataset VALUES (NULL, " + str(
            handRightResults[0]) + ", " + str(handRightResults[1]) + "," + str(
                handRightResults[2]
            ) + "," + str(handRightResults[3]) + "," + str(
                handRightResults[4]
            ) + "," + str(handRightResults[5]) + "," + str(
                handRightResults[6]
            ) + "," + str(handRightResults[7]) + "," + str(
                handRightResults[8]) + "," + str(
                    handRightResults[9]) + "," + str(
                        handRightResults[10]) + "," + str(
                            handRightResults[11]) + "," + str(
                                handRightResults[12]
                            ) + "," + str(handRightResults[13]) + "," + str(
                                handRightResults[14]
                            ) + "," + str(handRightResults[15]) + "," + str(
                                handRightResults[16]
                            ) + "," + str(handRightResults[17]) + "," + str(
                                handRightResults[18]
                            ) + "," + str(handRightResults[19]) + "," + str(
                                handRightResults[20]
                            ) + "," + str(handRightResults[21]) + "," + str(
                                handRightResults[22]
                            ) + "," + str(handRightResults[23]) + "," + str(
                                handRightResults[24]
                            ) + "," + str(handRightResults[25]) + "," + str(
                                handRightResults[26]
                            ) + "," + str(handRightResults[27]) + "," + str(
                                handRightResults[28]
                            ) + "," + str(handRightResults[29]) + "," + str(
                                handRightResults[30]
                            ) + "," + str(handRightResults[31]) + "," + str(
                                handRightResults[32]
                            ) + "," + str(handRightResults[33]) + "," + str(
                                handRightResults[34]
                            ) + "," + str(handRightResults[35]) + "," + str(
                                handRightResults[36]
                            ) + "," + str(handRightResults[37]) + "," + str(
                                handRightResults[38]
                            ) + "," + str(handRightResults[39]) + "," + str(
                                handRightResults[40]
                            ) + "," + str(handRightResults[41]) + "," + str(
                                handLeftResults[0]
                            ) + ", " + str(handLeftResults[1]) + "," + str(
                                handLeftResults[2]
                            ) + "," + str(handLeftResults[3]) + "," + str(
                                handLeftResults[4]
                            ) + "," + str(handLeftResults[5]) + "," + str(
                                handLeftResults[6]
                            ) + "," + str(handLeftResults[7]) + "," + str(
                                handLeftResults[8]
                            ) + "," + str(handLeftResults[9]) + "," + str(
                                handLeftResults[10]
                            ) + "," + str(handLeftResults[11]) + "," + str(
                                handLeftResults[12]
                            ) + "," + str(handLeftResults[13]) + "," + str(
                                handLeftResults[14]
                            ) + "," + str(handLeftResults[15]) + "," + str(
                                handLeftResults[16]
                            ) + "," + str(handLeftResults[17]) + "," + str(
                                handLeftResults[18]
                            ) + "," + str(handLeftResults[19]) + "," + str(
                                handLeftResults[20]
                            ) + "," + str(handLeftResults[21]) + "," + str(
                                handLeftResults[22]
                            ) + "," + str(handLeftResults[23]) + "," + str(
                                handLeftResults[24]
                            ) + "," + str(handLeftResults[25]) + "," + str(
                                handLeftResults[26]
                            ) + "," + str(handLeftResults[27]) + "," + str(
                                handLeftResults[28]
                            ) + "," + str(handLeftResults[29]) + "," + str(
                                handLeftResults[30]
                            ) + "," + str(handLeftResults[31]) + "," + str(
                                handLeftResults[32]
                            ) + "," + str(handLeftResults[33]) + "," + str(
                                handLeftResults[34]
                            ) + "," + str(handLeftResults[35]) + "," + str(
                                handLeftResults[36]
                            ) + "," + str(handLeftResults[37]) + "," + str(
                                handLeftResults[38]
                            ) + "," + str(handLeftResults[39]) + "," + str(
                                handLeftResults[40]
                            ) + "," + str(handLeftResults[41]) + "," + str(
                                poseResults[0]
                            ) + ", " + str(poseResults[1]) + "," + str(
                                poseResults[2]
                            ) + "," + str(poseResults[3]) + "," + str(
                                poseResults[4]
                            ) + "," + str(poseResults[5]) + "," + str(
                                poseResults[6]
                            ) + "," + str(poseResults[7]) + "," + str(
                                poseResults[8]
                            ) + "," + str(poseResults[9]) + "," + str(
                                poseResults[10]
                            ) + "," + str(poseResults[11]) + "," + str(
                                poseResults[12]
                            ) + "," + str(poseResults[13]) + "," + str(
                                poseResults[14]
                            ) + "," + str(poseResults[15]) + "," + str(
                                poseResults[16]
                            ) + "," + str(poseResults[17]) + "," + str(
                                poseResults[30]
                            ) + "," + str(poseResults[31]) + "," + str(
                                poseResults[32]) + "," + str(
                                    poseResults[33]) + "," + str(
                                        poseResults[34]) + "," + str(
                                            poseResults[35]) + "," + str(
                                                poseResults[36]) + "," + str(
                                                    poseResults[37]
                                                ) + "," + parentName + ");"
        crsr.execute(sql_command)

    connection.commit()
    connection.close()
def match_ann(fileName):
    js = json.loads(open(fileName).read())
    for items in js['people']:
        handRight = items["hand_right_keypoints_2d"]

    confPoints = helper.confidencePoints(handRight)
    confidence = helper.confidence(confPoints)
    if confidence > 10.2:
        handPoints = helper.removePoints(handRight)
        """
        experimenting with scaling 
        """
        p1 = [handPoints[0], handPoints[1]]
        p2 = [handPoints[18], handPoints[19]]
        distance = math.sqrt(((p1[0] - p2[0])**2) + ((p1[1] - p2[1])**2))

        Result, Points = scale.scalePoints(handPoints, distance)
        handRightResults, handRightPoints = move.centerPoints(handPoints)
        """
        extracting data from db
        """
        connection = sqlite3.connect("data\\db\\main_dataset.db")
        crsr = connection.cursor()

        # extracting x and y points
        sql = 'SELECT x1,y1'
        for x in range(2, 22):
            sql = sql + ',x' + str(x) + ',y' + str(x)
        sql = sql + ' FROM rightHandDataset WHERE 1'
        crsr.execute(sql)
        feature_res = crsr.fetchall()
        feature_res = np.asarray(feature_res)
        features = []
        for x in feature_res:
            features.append(x)

        # extracting labels
        crsr.execute('SELECT label FROM rightHandDataset WHERE 1')
        label_res = crsr.fetchall()
        labels = []
        for x in label_res:
            labels.append(x)

        #creating labelEncoder
        le = preprocessing.LabelEncoder()
        # Converting string labels into numbers.
        label_encoded = le.fit_transform(labels)

        label_encoded = to_categorical(label_encoded)

        X_train, X_test, y_train, y_test = train_test_split(features,
                                                            label_encoded,
                                                            test_size=0.2)

        scaler = StandardScaler().fit(X_train)
        X_train = scaler.transform(X_train)
        X_test = scaler.transform(X_test)

        y_pred = model.predict(scaler.transform(np.array([handRightResults])))

        C = np.argmax(y_pred)

        result = le.inverse_transform([C])

        return result[0]
    else:
        return "no confidence"
def capture_alphabet_dataset(sec):

    global remfileNames
    """
    ----------------------Start OpenPoseDemo.exe----------------------
    --render_pose 0  --display 0
    """
    os.chdir('bin\\openpose')
    print('Starting OpenPose')
    subprocess.Popen(
        'bin\\OpenPoseDemo.exe --hand  --write_json ..\\..\\Keypoints   --number_people_max 1',
        shell=True)
    os.chdir('..\\..')
    """
    ----------------------Creating temp folder----------------------
    """
    dirName = 'Keypoints'
    init_file = 'PSL\\000000000000_keypoints.json'

    try:
        # Create target Directory
        os.mkdir(dirName)
        os.mkdir("gui\\captured_images")
        os.mkdir("gui\\temp_images")

        # copy initializing file in directory
        shutil.copy(init_file, dirName)
        print("Directory ", dirName, " Created ")
    except FileExistsError:
        print("Directory ", dirName, " already exists")
    """
    ----------------------Live View----------------------
    """

    #    shutil.copy('PSL\\000000000000_keypoints.json', 'Keypoints')
    #    filePlotName = '000000000000_keypoints.json'
    t = time.time() + sec
    while time.time() <= t:
        eel.sleep(0.05)


#        for entry in os.scandir('Keypoints'):
#            if entry.is_file():
#                if os.path.splitext(entry)[1] == ".json":
#                    filePlotName = entry.name
#
#        try:
#            js = json.loads(open('Keypoints\\' + filePlotName).read())
#        except ValueError:
#            print('Decoding JSON has failed')
#            pass
#
#        # extract 'hand_right_keypoints_2d' from json file
#        for items in js['people']:
#            pose = items["pose_keypoints_2d"]
#            handRight = items["hand_right_keypoints_2d"]
#            handLeft = items["hand_left_keypoints_2d"]
#
#        pose_points = helper.removePoints(pose)
#        posePoints = helper.join_points(pose_points)
#
#        #  function to remove confidence points
#        hand_right_Points = helper.removePoints(handRight)
#        handRightPoints = helper.join_points(hand_right_Points)
#
#        hand_left_points = helper.removePoints(handLeft)
#        handLeftPoints = helper.join_points(hand_left_points)
#
#        frame = plotPose(posePoints, handRightPoints, handLeftPoints)
#
#        cv2.imwrite('gui\\temp_images\\' + filePlotName + '.jpg', frame)
#        # reset image
#        frame = cv2.imread("PSL\\BLACK_background.jpg")
#        print("saad")
#        eel.get_fileName(filePlotName)
#        filePlotName = ''

#    eel.sleep(sec)
#  Kill openpose
    os.system("taskkill /f /im  OpenPoseDemo.exe")
    """
    ---------------------- Auto Remove files----------------------
    """
    conf_thershold = 10
    fileNames = []
    #scan temporary folder
    for entry in os.scandir('Keypoints'):
        # store the name if entry is file and file is of ext .json
        if entry.is_file():
            if os.path.splitext(entry)[1] == ".json":
                fileNames.append(entry.name)

    # traverse fileNames[]
    for x in range(len(fileNames)):
        # load each file from fileName[]
        js = json.loads(open('Keypoints\\' + fileNames[x]).read())
        # extract 'hand_right_keypoints_2d' from json file
        for items in js['people']:
            handRight = items["hand_right_keypoints_2d"]

        # extract confidence points
        confPoints = helper.confidencePoints(handRight)
        # add all confidence points
        confidence = helper.confidence(confPoints)
        print(confidence)
        # remove file if confidence is less than threshold
        if confidence < conf_thershold:
            os.remove('Keypoints\\' + fileNames[x])
    """
    ----------------------plot and save----------------------
    """
    background = 'big_background.png'
    fileNames = []
    #scan temporary folder
    for entry in os.scandir('Keypoints'):
        # store the name if entry is file and file is of ext .json
        if entry.is_file():
            if os.path.splitext(entry)[1] == ".json":
                fileNames.append(entry.name)

    # read background image
    frame = cv2.imread(background)

    i = 1

    for x in range(len(fileNames)):
        # load each file from fileName[]
        js = json.loads(open('Keypoints\\' + fileNames[x]).read())
        # extract 'hand_right_keypoints_2d' from json file
        for items in js['people']:
            handRight = items["hand_right_keypoints_2d"]

        #  function to remove confidence points
        handPoints = helper.removePoints(handRight)

        p1 = [handPoints[0], handPoints[1]]
        p2 = [handPoints[18], handPoints[19]]
        distance = math.sqrt(((p1[0] - p2[0])**2) + ((p1[1] - p2[1])**2))

        Result, Points = scale.dummy_scalePoints(handPoints, distance)

        handRightResults, handRightPoints = move.dummy_centerPoints(Result)

        frame = plot.plot_dataset(handRightPoints, 'black')

        cv2.imwrite('gui\\captured_images\\' + str(i) + '.jpg', frame)
        i += 1
        """
        ----------------------get ref to delete files----------------------
        """

        for entry in os.scandir('Keypoints'):
            if entry.is_file():
                if os.path.splitext(entry)[1] == ".json":
                    remfileNames.append(entry.name)
        """