Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import torch
|
| 2 |
import streamlit as st
|
| 3 |
import numpy as np
|
|
@@ -14,7 +15,8 @@ st.title('Upload an image file to detection')
|
|
| 14 |
col1, col2, col3 = st.columns([0.5, 0.3, 0.2])
|
| 15 |
|
| 16 |
with col1:
|
| 17 |
-
|
|
|
|
| 18 |
uploaded_image_zero_file = st.file_uploader("Choose an image file (zero)")
|
| 19 |
|
| 20 |
imageLocation = st.empty()
|
|
@@ -31,6 +33,9 @@ with col1:
|
|
| 31 |
if st.button('detect'):
|
| 32 |
|
| 33 |
draw = ImageDraw.Draw(image)
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
for prediction in predictions:
|
| 36 |
box = prediction["box"]
|
|
@@ -40,6 +45,11 @@ with col1:
|
|
| 40 |
xmin, ymin, xmax, ymax = box.values()
|
| 41 |
draw.rectangle((xmin, ymin, xmax, ymax), outline="red", width=5)
|
| 42 |
draw.text((xmin, ymin), f"{label}: {round(score,5)}", fill="white")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
imageLocation.image(image)
|
| 45 |
st.write(predictions)
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
import torch
|
| 3 |
import streamlit as st
|
| 4 |
import numpy as np
|
|
|
|
| 15 |
col1, col2, col3 = st.columns([0.5, 0.3, 0.2])
|
| 16 |
|
| 17 |
with col1:
|
| 18 |
+
|
| 19 |
+
st.header('flyer')
|
| 20 |
uploaded_image_zero_file = st.file_uploader("Choose an image file (zero)")
|
| 21 |
|
| 22 |
imageLocation = st.empty()
|
|
|
|
| 33 |
if st.button('detect'):
|
| 34 |
|
| 35 |
draw = ImageDraw.Draw(image)
|
| 36 |
+
|
| 37 |
+
arrImg = np.array(image)
|
| 38 |
+
imageCv = cv2.cvtColor(arrImg, cv2.COLOR_RGB2BGR)
|
| 39 |
|
| 40 |
for prediction in predictions:
|
| 41 |
box = prediction["box"]
|
|
|
|
| 45 |
xmin, ymin, xmax, ymax = box.values()
|
| 46 |
draw.rectangle((xmin, ymin, xmax, ymax), outline="red", width=5)
|
| 47 |
draw.text((xmin, ymin), f"{label}: {round(score,5)}", fill="white")
|
| 48 |
+
|
| 49 |
+
crop_img = imageCv[ymin:ymax, xmin:xmax]
|
| 50 |
+
if crop_img.size > 0:
|
| 51 |
+
cv2.imwrite("data/cropped_image_{}.jpg".format(i), crop_img)
|
| 52 |
+
i += 1
|
| 53 |
|
| 54 |
imageLocation.image(image)
|
| 55 |
st.write(predictions)
|