From 1b2accdc1d2a761dbe21a608e60ea32ca973e730 Mon Sep 17 00:00:00 2001
From: Kevin Allen <kma1660@gmail.com>
Date: Sat, 28 Apr 2018 16:48:04 -0400
Subject: [PATCH] SCAN THE CODE: refactor classifier using base class main
 function

---
 .../{stc_datasets.yaml => stc/datasets.yaml}  |  0
 .../{stc_labels.json => stc/labels.json}      |  0
 .../{stc_colors.csv => stc/training.csv}      |  0
 .../scan_the_code_classifier.py               | 20 +++++----------
 .../totems_color_classifier.py                | 25 +++++++++++++++++++
 5 files changed, 31 insertions(+), 14 deletions(-)
 rename perception/navigator_vision/config/{stc_datasets.yaml => stc/datasets.yaml} (100%)
 rename perception/navigator_vision/config/{stc_labels.json => stc/labels.json} (100%)
 rename perception/navigator_vision/config/{stc_colors.csv => stc/training.csv} (100%)
 create mode 100755 perception/navigator_vision/navigator_vision/totems_color_classifier.py

diff --git a/perception/navigator_vision/config/stc_datasets.yaml b/perception/navigator_vision/config/stc/datasets.yaml
similarity index 100%
rename from perception/navigator_vision/config/stc_datasets.yaml
rename to perception/navigator_vision/config/stc/datasets.yaml
diff --git a/perception/navigator_vision/config/stc_labels.json b/perception/navigator_vision/config/stc/labels.json
similarity index 100%
rename from perception/navigator_vision/config/stc_labels.json
rename to perception/navigator_vision/config/stc/labels.json
diff --git a/perception/navigator_vision/config/stc_colors.csv b/perception/navigator_vision/config/stc/training.csv
similarity index 100%
rename from perception/navigator_vision/config/stc_colors.csv
rename to perception/navigator_vision/config/stc/training.csv
diff --git a/perception/navigator_vision/navigator_vision/scan_the_code_classifier.py b/perception/navigator_vision/navigator_vision/scan_the_code_classifier.py
index dfe2683d..34f223ab 100755
--- a/perception/navigator_vision/navigator_vision/scan_the_code_classifier.py
+++ b/perception/navigator_vision/navigator_vision/scan_the_code_classifier.py
@@ -10,24 +10,16 @@ class ScanTheCodeClassifier(GaussianColorClassifier):
     def __init__(self):
         rospack = RosPack()
         path = rospack.get_path('navigator_vision')
-        self.features_file = os.path.join(path, 'config/stc_colors.csv')
-        super(ScanTheCodeClassifier, self).__init__(ScanTheCodeClassifier.CLASSES)
-
-    def train_from_csv(self):
-        return super(ScanTheCodeClassifier, self).train_from_csv(self.features_file)
-
-    def save_csv(self, features, classes):
-        return super(ScanTheCodeClassifier, self).save_csv(features, classes, filename=self.features_file)
+        training_file = os.path.join(path, 'config/stc/training.csv')
+        labelfile = os.path.join(path, 'config/stc/labels.json')
+        super(ScanTheCodeClassifier, self).__init__(ScanTheCodeClassifier.CLASSES,
+                                                    training_file=training_file, labelfile=labelfile)
 
 
 if __name__ == '__main__':
     '''
-    When run as an executable, saves the training features to a csv file
-    2 arguemnts: labelbox.io labelfile, and image directory
+    Can be run as executable to extract features or check accuracy score
     '''
     import sys
-    labelfile = sys.argv[1]
-    image_dir = sys.argv[2]
     s = ScanTheCodeClassifier()
-    features, classes = s.extract_labels(labelfile, image_dir)
-    s.save_csv(features, classes)
+    s.main(sys.argv[1:])
diff --git a/perception/navigator_vision/navigator_vision/totems_color_classifier.py b/perception/navigator_vision/navigator_vision/totems_color_classifier.py
new file mode 100755
index 00000000..4613500a
--- /dev/null
+++ b/perception/navigator_vision/navigator_vision/totems_color_classifier.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python
+from mil_vision_tools import GaussianColorClassifier
+from rospkg import RosPack
+import os
+
+
+class TotemsColorClassifier(GaussianColorClassifier):
+    CLASSES = ['{}_totem'.format(color) for color in ['white', 'red', 'green', 'blue', 'yellow']]
+
+    def __init__(self):
+        rospack = RosPack()
+        path = rospack.get_path('navigator_vision')
+        training_file = os.path.join(path, 'config/totems_color/training.csv')
+        labelfile = os.path.join(path, 'config/totems_color/labels.json')
+        super(TotemsColorClassifier, self).__init__(self.CLASSES,
+            training_file=training_file, labelfile=labelfile)
+
+
+if __name__ == '__main__':
+    '''
+    Can be run as executable to extract features or check accuracy score
+    '''
+    import sys
+    c = TotemsColorClassifier()
+    c.main(sys.argv[1:])