diff --git a/README.md b/README.md new file mode 100644 index 0000000..4e52d05 --- /dev/null +++ b/README.md @@ -0,0 +1,65 @@ +# test + +outputs `Yes` if the supplied image contains a bus and `No` if it does not + +## usage + +syntax: `./test.py [IMAGE]` + +### example 1 + +testing with the following image: + +![](img/bus.jpg) + +```bash +./test.py img/bus.jpg +``` + +output: + +``` + +image 1/1 /home/ja/git/YOLOv8_test_example/img/bus.jpg: 640x480 4 persons, 1 bus, 1 stop sign, 20.1ms +Speed: 1.0ms preprocess, 20.1ms inference, 0.7ms postprocess per image at shape (1, 3, 640, 480) +Yes +Confidence: 87.3% +``` + +### example 2 + +testing with the following image: + +![](img/notabus.png) + +```bash +./test.py img/notabus.png +``` + +output: + +``` +image 1/1 /home/ja/git/YOLOv8_test_example/img/notabus.png: 384x640 (no detections), 17.4ms +Speed: 0.9ms preprocess, 17.4ms inference, 0.4ms postprocess per image at shape (1, 3, 384, 640) +No +``` + +### example 3 + +testing with the following image: + +![](img/bus2.png) + +```bash +./test.py img/bus2.png +``` + +output: + +``` +image 1/1 /home/ja/git/YOLOv8_test_example/img/bus2.png: 384x640 (no detections), 16.4ms +Speed: 1.1ms preprocess, 16.4ms inference, 0.3ms postprocess per image at shape (1, 3, 384, 640) +No +``` + +Note that another cartoon image of a bus did register as a bus. diff --git a/bus.jpg b/img/bus.jpg similarity index 100% rename from bus.jpg rename to img/bus.jpg diff --git a/bus.png b/img/bus.png similarity index 100% rename from bus.png rename to img/bus.png diff --git a/bus2.png b/img/bus2.png similarity index 100% rename from bus2.png rename to img/bus2.png diff --git a/bus3.jpg b/img/bus3.jpg similarity index 100% rename from bus3.jpg rename to img/bus3.jpg diff --git a/bus4.jpg b/img/bus4.jpg similarity index 100% rename from bus4.jpg rename to img/bus4.jpg diff --git a/img/manybuses.jpg b/img/manybuses.jpg new file mode 100644 index 0000000..026edb6 Binary files /dev/null and b/img/manybuses.jpg differ diff --git a/notabus.png b/img/notabus.png similarity index 100% rename from notabus.png rename to img/notabus.png diff --git a/img/van.jpeg b/img/van.jpeg new file mode 100644 index 0000000..7fb8e9c Binary files /dev/null and b/img/van.jpeg differ diff --git a/readme.MD b/readme.MD deleted file mode 100755 index 027d20f..0000000 --- a/readme.MD +++ /dev/null @@ -1,7 +0,0 @@ -it works on pictures of busses but not the hand-drawn image i made. - -This program tells you whether or not the selected image is a bus. - -python3 test.py - -To change the file to run the operation on, change this line in the source code: results = model("bus4.jpg") diff --git a/test.py b/test.py old mode 100644 new mode 100755 index 67c0064..29edd2f --- a/test.py +++ b/test.py @@ -1,10 +1,16 @@ +#!/usr/bin/env python3 + +import sys + from ultralytics import YOLO +image_path = sys.argv[1] + # Load the small pretrained YOLOv8 object-detection model. model = YOLO("yolov8n.pt") # Run object detection on a test image. -results = model("bus4.jpg") +results = model(image_path) has_bus = False max_confidence = 0.0 @@ -13,7 +19,7 @@ for result in results: class_names = result.names detected_classes = result.boxes.cls.tolist() confidences = result.boxes.conf.tolist() - + # Check each detected object and its matching confidence score for cls_id, conf in zip(detected_classes, confidences): if class_names[int(cls_id)] == "bus":