-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrone.py
More file actions
37 lines (29 loc) · 930 Bytes
/
drone.py
File metadata and controls
37 lines (29 loc) · 930 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
30
31
32
33
34
35
36
37
import numpy as np
from classes.image import Image
import os
from math import ceil
from main import Main
from main import loadAll
trained_data_file = 'trained_data'
def createClassifier():
return Main().classifier
def loadDir(dirname):
print("Loading data " + dirname)
names = []
X = []
imagesList = os.listdir(dirname)
numbersOfImages = len(imagesList)
for file in imagesList:
names.append(file)
print(len(X)+1, '/', numbersOfImages, end = '\r')
img = Image(dirname + file)
X.append(img.getDescriptors())
print(ceil((len(X) / numbersOfImages)*100), '%', end = '\r')
return X, names
def predict_main(dirName):
X, names = loadDir(dirName)
X_train, y_train = loadAll() # loadData(trained_data_file)
classifier = createClassifier()
classifier.fit(X_train, y_train)
predictions = classifier.predict(X)
return [names, predictions]