コード例 #1
0
def preProcessing(filename, folderPath):
    print(filename)
    d = showpoints('Original Plot', filename, folderPath)
    d = interpolation(d)
    final_features = features(d)
    #print(filename[0:2])
    target = int(filename[0:2])
    final_features.insert(0, target)
    # print(final_features)
    # print(len(final_features))
    title_row = ['Label']
    for i in range(360):
        title_row.append(i + 1)
    filename = os.path.expanduser("training_dataset_telugu.csv")
    # print(filename)
    if os.path.exists(filename):
        # print('exists')
        append_write = 'a' # append if already exists...
    else:
        # print('not exist')
        append_write = 'w+' # make a new file if not

    myFile = open(filename, append_write, newline='')
    with myFile:
        writer = csv.writer(myFile)
        writer.writerow(final_features)
    myFile.close()
def strokeSeg(content):
 strokesList = []
 tempStrokeList = []
 strokeLabelsList = []
# folderPath = r'C:\Users\Sanya\PycharmProjects\Online_Indic_Handwriting_Recognition'
# fileName = input('Enter the file name:')
# path =   fileName

#with open('Krish.txt', 'r', encoding='utf8') as f:
    #content = f.readlines()

# content=44(1).txt
# print(content)
 content = [z.strip().split(',') for z in content]
# print(content)
 for item in content:
    if (item[2] == '0'):
        item[0] = float(item[0])
        item[1] = float(item[1])
        item[2] = float(item[2])
        tempStrokeList.append(item)
    else:
        strokesList.append(tempStrokeList)
        tempStrokeList = []

# print(strokesList[1])
 for stroke in strokesList:
    s = interpolation(stroke)
    final_features = features(s)
    strokeLabel = predictStrokeLabel(final_features)
    #print(strokeLabel)
    strokeLabelsList.append(strokeLabel)

 strokeLabelsList.sort()
#print(strokeLabelsList)
 strLabel = '.'.join(str(e) for e in strokeLabelsList)
 print(strLabel)

 fo = open("hindifinal.txt", "r",encoding="utf8")

 #letter = ["पुनः पय।स करें।"]
 letter= ["Try"]
 for i in fo:
  i=i.rstrip() #returns each line as string removing the last \n character
  if strLabel == i:
     letter[0] =next(fo)
    # print(next(fo), end='')
     break


 fo.close()

# compareLabel(strokeLabelsList)
# return strokeLabelsList

 return letter
def strokeSeg(content):
    strokesList = []
    tempStrokeList = []
    strokeLabelsList = []

    # folderPath = 'C:\\Users\\DEDSEC\\OneDrive\\Documents\\VSCode\\Minor Project\\On-Line-Handwriting-Recognition\\Letter Test Samples\\Working'

    # fileName = input('Enter the file name:')
    # path = folderPath + '\\'+ fileName

    # with open(path) as f:
    #     content = f.readlines()

    content = [z.strip().split(',') for z in content]
    for item in content:
        if (item[2] == '0'):
            item[0] = float(item[0])
            item[1] = float(item[1])
            item[2] = float(item[2])
            tempStrokeList.append(item)
        else:
            strokesList.append(tempStrokeList)
            tempStrokeList = []

    #print(strokesList[1])
    for stroke in strokesList:

        s = interpolation(stroke)
        final_features = features(s)
        strokeLabel = predictStrokeLabel(final_features)
        print(strokeLabel)
        strokeLabelsList.append(strokeLabel)

    strokeLabelsList.sort()

    return strokeLabelsList
コード例 #4
0
def strokeSeg(content):
    strokesList = []
    tempStrokeList=[]
    strokeLabelsList = []
    x = pd.read_csv("training_dataset.csv")
    print(np.isnan(x))

    c = np.array(x)
    y = c[:, 0]
    x.drop(["Class"], axis=1, inplace=True)
    a = np.array(x)

    lab_enc = preprocessing.LabelEncoder()
    clf = SVC(C=1.0, kernel='poly', degree=3, gamma=2)
    clf.fit(x, y)

    def predictStrokeLabel(featuresList,clf):

        result = clf.predict([featuresList])

        return int(result[0])
    # folderPath = 'C:\\Users\\DEDSEC\\OneDrive\\Documents\\VSCode\\Minor Project\\On-Line-Handwriting-Recognition\\Letter Test Samples\\Working'

    # fileName = input('Enter the file name:')
    # path = folderPath + '\\'+ fileName

    # with open(path) as f:
    #     content = f.readlines()

    content = [z.strip().split(',') for z in content]
    for item in content:
        if(item[2]=='0'):
            item[0]=float(item[0])
            item[1]=float(item[1])
            item[2]=float(item[2])
            tempStrokeList.append(item)
        else:
            strokesList.append(tempStrokeList)
            tempStrokeList=[]

    #print(strokesList[1])
    for stroke in strokesList:
        
        s = interpolation(stroke)
        final_features = features(s)
        strokeLabel = predictStrokeLabel(final_features,clf)
        print(strokeLabel)
        strokeLabelsList.append(strokeLabel)

    strokeLabelsList.sort()

    #return strokeLabelsList
    strLabel = '.'.join(str(e) for e in strokeLabelsList)
    print(strLabel)

    fo = open("hindidic.txt", "r",encoding="utf8")

 #letter = ["पुनः पय।स करें।"]
    letter= ["Try"]
    for i in fo:
     i=i.rstrip() #returns each line as string removing the last \n character
     if strLabel == i:
      letter[0] =next(fo).rstrip()
    # print(next(fo), end='')
      break
    fo.close()

# compareLabel(strokeLabelsList)
# return strokeLabelsList
    print(letter)
    return letter