NotShrirang commited on
Commit
cf9c906
·
1 Parent(s): f760b79

fix: display bounding boxes

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. app.py +23 -4
  3. models/best.pt +3 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ venv
app.py CHANGED
@@ -1,8 +1,11 @@
1
  import streamlit as st
2
  from ultralytics import YOLO
3
  from PIL import Image
 
 
 
4
 
5
- model = YOLO("./models/yolov8-best.pt")
6
  classNames = ["license-plate", "vehicle"]
7
 
8
  st.title("Number Plate and Vehicle Detection using YOLOv8")
@@ -12,9 +15,25 @@ st.write("This is a web app to detect number plates and vehicles in images using
12
  image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
13
 
14
  if image is not None:
 
15
  st.image(image, caption="Uploaded Image", use_column_width=True)
16
- img = image.read()
17
- img = Image.open(img)
18
  results = model.predict(img, conf=0.5)
19
  json_results = results[0].tojson()
20
- st.write(json_results)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from ultralytics import YOLO
3
  from PIL import Image
4
+ import json
5
+ import cv2
6
+ import numpy as np
7
 
8
+ model = YOLO("./models/best.pt")
9
  classNames = ["license-plate", "vehicle"]
10
 
11
  st.title("Number Plate and Vehicle Detection using YOLOv8")
 
15
  image = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
16
 
17
  if image is not None:
18
+ st.header("Original Image")
19
  st.image(image, caption="Uploaded Image", use_column_width=True)
20
+ st.info("Detecting...")
21
+ img = Image.open(image)
22
  results = model.predict(img, conf=0.5)
23
  json_results = results[0].tojson()
24
+ encoded_json_results = str(json_results).replace("\n", '').replace(" ", '')
25
+ encoded_json_results = json.loads(encoded_json_results)
26
+ for pred in encoded_json_results:
27
+ x1 = int(pred['box']['x1'])
28
+ y1 = int(pred['box']['y1'])
29
+ x2 = int(pred['box']['x2'])
30
+ y2 = int(pred['box']['y2'])
31
+
32
+ img = np.array(img)
33
+ img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
34
+ cv2.rectangle(img, (x1, y1), (x2, y2), (0, 0, 255), 2)
35
+ cv2.putText(img, pred['name'], (x1, y1), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
36
+ st.header("Detected Image")
37
+ st.image(img, caption="Detected Image", use_column_width=True)
38
+ st.header("JSON Results")
39
+ st.write(encoded_json_results)
models/best.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a5e6ccbbf682c831317053a88ca70f463790dee7c9760e4323f5f9d6f39464ce
3
+ size 22470702