forked from binhfdv/DS102.K21_fruits_classifier
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.py
More file actions
31 lines (26 loc) · 803 Bytes
/
functions.py
File metadata and controls
31 lines (26 loc) · 803 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import glob
import cv2
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.metrics import confusion_matrix
labels = []
with open('labels.txt', 'r') as lb:
for _ in lb:
labels.append(_.strip())
labels = sorted(labels)
def load_Data(X, Y, data_path):
for label_i in range(len(labels)):
for im_path in glob.glob(r"{0}\\{1}\\*.jpg".format(data_path, str(labels[label_i]))):
X.append(cv2.imread(im_path))
Y.append(labels[label_i])
return X, Y
def rbgToGrayAndResize(X):
X_shaped = []
for i in range(len(X)):
grey = cv2.cvtColor(X[i], cv2.COLOR_BGR2GRAY)
# img = cv2.resize(grey,(50, 50))
X_shaped.append(grey)
X_shaped = np.array(X_shaped)
return X_shaped