Advertisement
brospresident

Untitled

Nov 17th, 2021
749
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. import numpy as np
  2. import pandas as pd
  3. import matplotlib.pyplot as plt
  4. from skimage.io import imread
  5. from skimage.feature import hog
  6. from skimage.filters import threshold_otsu
  7.  
  8.  
  9.  
  10. #Citim baza de date pentru antrenare si testare
  11. df = pd.read_csv('eye_data_lab4.csv')
  12. df_t = pd.read_csv('eye_data_lab4_test.csv')
  13.  
  14. #pandas.DataFrame.nunique finds the unique elements(lines) of a dataset
  15. df['label'].nunique()
  16.  
  17. #Print dataframe
  18. print(df.head())
  19.  
  20. # Eliminam coloana label pentru a ramane doar cu caracterisiticile pozelor
  21. features = df.drop('label', axis=1)
  22. label = df['label']
  23.  
  24. #convertim tipul de date din panda in ndarray
  25. testFeatures = df_t.to_numpy()
  26.  
  27. #Extragem dimensiunea matricei de caracteristici
  28. n, m = features.shape
  29.  
  30. # Construiti si rezolvati problema cmmp utilizand comanda lstqr
  31. classifier = np.linalg.lstsq(features, label, rcond=None)[0]
  32.  
  33. i = input('Introduceti o valoare intre 0 si 3: ')
  34.  
  35. #Afisarea imaginii testate
  36. img = imread(i +'.jpg')
  37.  
  38. plt.axis("off")
  39. plt.imshow(img,cmap="gray")
  40. print(img.shape)
  41.  
  42. thresh = threshold_otsu(img)
  43. binary = img > thresh
  44. testFeatures = hog(binary, orientations=1, pixels_per_cell=(1,1), cells_per_block=(1,1), visualize=False, normalize=True)
  45.  
  46. # Testati clasificatorul, cu alte cuvinte preziceti test_label
  47. test_label = np.dot(testFeatures, classifier)
  48.  
  49. if test_label.all() >= 0:
  50.     print('Ochiul este deschis')
  51. else: print('Ochiul este inchis')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement