Skip to content

Commit

Permalink
fix integrated system
Browse files Browse the repository at this point in the history
  • Loading branch information
Hironsan committed Sep 14, 2016
1 parent 11b1e14 commit 1714ecb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
3 changes: 1 addition & 2 deletions boss_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ def read_image(file_path):
def extract_data(path):
images, labels = traverse_dir(path)
images = np.array(images)
dic = dict([(label, i) for i, label in enumerate(set(labels))])
labels = np.array([dic[label] for label in labels])
labels = np.array([0 if label.endswith('boss') else 1 for label in labels])

return images, labels
26 changes: 17 additions & 9 deletions boss_train.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ def predict(self, image):
if image.shape != (1, 3, IMAGE_SIZE, IMAGE_SIZE):
image = resize_with_pad(image)
image = image.reshape((1, 3, IMAGE_SIZE, IMAGE_SIZE))
result = self.model.predict_proba(image)
print(result)
result = self.model.predict_classes(image)
# result = self.model.predict_proba(image)


return result[0]

Expand All @@ -156,24 +158,30 @@ def evaluate(self, dataset):

dataset = Dataset()
dataset.read()

"""
model = Model()
model.build_model(dataset)
model.train(dataset, nb_epoch=10)
model.save()

"""
model = Model()
model.load()
model.evaluate(dataset)
for image, label in zip(dataset.X_test, dataset.Y_test):
model.predict(image.reshape(1, 3, IMAGE_SIZE, IMAGE_SIZE))
print(label)
#for image, label in zip(dataset.X_test, dataset.Y_test):
# model.predict(image.reshape(1, 3, IMAGE_SIZE, IMAGE_SIZE))
# print(label)
"""
import cv2
import os
#image = cv2.imread('./data/other/Abdel_Nasser_Assidi_0002.jpg')
model = Model()
model.load()
image = cv2.imread('test.jpg')
image = resize_with_pad(image)
image = image.reshape((1, 3, IMAGE_SIZE, IMAGE_SIZE))
result = model.predict(image)
print(result)
"""
"""
for file_name in os.listdir('./data/boss'):
if file_name.endswith('.jpg'):
print(file_name)
Expand Down
13 changes: 8 additions & 5 deletions camera_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def run(self):
model = Model()
model.load()
while True:
ret, frame = cap.read()
_, frame = cap.read()

# グレースケール変換
frame_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

Expand All @@ -90,11 +91,13 @@ def run(self):

x, y = rect[0:2]
width, height = rect[2:4]
image = frame[y-50: y + height, x: x + width + 50]
cv2.imwrite('test.jpg', image)
#image = frame[y - 50: y + height, x: x + width + 50]
image = frame[y - 50: y + height, x: x + width]
#image = frame[y: y + height, x: x + width]
#now = datetime.now().strftime('%Y%m%d%H%M%S')
#cv2.imwrite(now + '.jpg', image)
result = model.predict(image)
print(result)
if result == 1: # boss
if result == 0: # boss
print('Boss is approaching')
show_image()
else:
Expand Down

0 comments on commit 1714ecb

Please sign in to comment.