def main(): print("Running Task") camera = Camera() d = Detector() rs = d.detect_image(camera.capture()) print(rs) for obj, confidence in rs.items(): print('Object {} : Confidence {}'.format(obj, confidence))
def test_detector_image(self): # Create Localizer cfg_path = './data/yolo/full/trafficsigns.cfg' weights_path = './data/yolo/full/trafficsigns.weights' threshold = 0.24 localizer = Localizer(cfg_path, weights_path, threshold, gpu=0.0) # Create cropper crop_percent = 0.25 force_square = True cropper = Cropper(crop_percent, force_square) # Create classifier model_path = './data/classifier/trafficsigns.json' weights_path = './data/classifier/trafficsigns.h5' labels_path = './data/classifier/classes.txt' threshold = 0.5 classifier = Classifier(model_path, weights_path, labels_path, threshold) # Create detection pipeline detection_pipeline = DetectionPipeline(localizer, cropper, classifier) # Create detector images_path = './data/classifier/classes/' sounds_path = './data/sounds/' detector = Detector(detection_pipeline, images_path, sounds_path) # Detect on image img = cv2.imread('./tests/data/test.png') image, detections = detector.detect_image(img, show_confidence=True, return_image=True) true_detections = [{ 'class_id': 15, 'coordinates': [1434, 456, 1590, 612], 'label': 'max-60', 'confidence': 1.0 }] assert detections == true_detections
def test_detector_image_output_json(self): # Create Localizer cfg_path = './data/yolo/full/trafficsigns.cfg' weights_path = './data/yolo/full/trafficsigns.weights' threshold = 0.24 localizer = Localizer(cfg_path, weights_path, threshold, gpu=0.0) # Create cropper crop_percent = 0.25 force_square = True cropper = Cropper(crop_percent, force_square) # Create classifier model_path = './data/classifier/trafficsigns.json' weights_path = './data/classifier/trafficsigns.h5' labels_path = './data/classifier/classes.txt' threshold = 0.5 classifier = Classifier(model_path, weights_path, labels_path, threshold) # Create detection pipeline detection_pipeline = DetectionPipeline(localizer, cropper, classifier) # Create detector images_path = './data/classifier/classes/' sounds_path = './data/sounds/' detector = Detector(detection_pipeline, images_path, sounds_path) # Detect on image img = cv2.imread('./tests/data/test.png') output_filename = './tests/data/detector_image.json' detections = detector.detect_image(img, output=output_filename) assert os.path.exists(output_filename) == True