Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import pandas as pd
- import matplotlib.pyplot as plt
- from skimage.io import imread
- from skimage.feature import hog
- from skimage.filters import threshold_otsu
- #Citim baza de date pentru antrenare si testare
- df = pd.read_csv('eye_data_lab4.csv')
- df_t = pd.read_csv('eye_data_lab4_test.csv')
- #pandas.DataFrame.nunique finds the unique elements(lines) of a dataset
- df['label'].nunique()
- #Print dataframe
- print(df.head())
- # Eliminam coloana label pentru a ramane doar cu caracterisiticile pozelor
- features = df.drop('label', axis=1)
- label = df['label']
- #convertim tipul de date din panda in ndarray
- testFeatures = df_t.to_numpy()
- #Extragem dimensiunea matricei de caracteristici
- n, m = features.shape
- # Construiti si rezolvati problema cmmp utilizand comanda lstqr
- classifier = np.linalg.lstsq(features, label, rcond=None)[0]
- i = input('Introduceti o valoare intre 0 si 3: ')
- #Afisarea imaginii testate
- img = imread(i +'.jpg')
- plt.axis("off")
- plt.imshow(img,cmap="gray")
- print(img.shape)
- thresh = threshold_otsu(img)
- binary = img > thresh
- testFeatures = hog(binary, orientations=1, pixels_per_cell=(1,1), cells_per_block=(1,1), visualize=False, normalize=True)
- # Testati clasificatorul, cu alte cuvinte preziceti test_label
- test_label = np.dot(testFeatures, classifier)
- if test_label.all() >= 0:
- print('Ochiul este deschis')
- else: print('Ochiul este inchis')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement