Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -20,6 +20,20 @@ os.makedirs(f"{BASE_DIR}/input",exist_ok=True)
|
|
20 |
sys.path.append(f'{BASE_DIR}/yolov7')
|
21 |
os.system("pip install yolov7-package==0.0.12")
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def detect(opt, save_img=False):
|
24 |
# from models.experimental import attempt_load
|
25 |
# from utils.datasets import LoadStreams, LoadImages
|
@@ -34,7 +48,6 @@ def detect(opt, save_img=False):
|
|
34 |
scale_coords, xyxy2xywh, strip_optimizer, set_logging, increment_path
|
35 |
from yolov7_package.utils.torch_utils import select_device, load_classifier, time_synchronized, TracedModel
|
36 |
from yolov7_package.utils.datasets import LoadStreams, LoadImages
|
37 |
-
from yolov7_package.utils.plots import plot_one_box
|
38 |
|
39 |
bbox = {}
|
40 |
source, weights, view_img, save_txt, imgsz, trace = opt.source, opt.weights, opt.view_img, opt.save_txt, opt.img_size, not opt.no_trace
|
|
|
20 |
sys.path.append(f'{BASE_DIR}/yolov7')
|
21 |
os.system("pip install yolov7-package==0.0.12")
|
22 |
|
23 |
+
def plot_one_box(x, img, color=None, label=None, line_thickness=3):
|
24 |
+
# Plots one bounding box on image img
|
25 |
+
tl = line_thickness or round(0.002 * (img.shape[0] + img.shape[1]) / 2) + 1 # line/font thickness
|
26 |
+
color = color or [random.randint(0, 255) for _ in range(3)]
|
27 |
+
c1, c2 = (int(x[0]), int(x[1])), (int(x[2]), int(x[3]))
|
28 |
+
cv2.rectangle(img, c1, c2, color, thickness=tl, lineType=cv2.LINE_AA)
|
29 |
+
if label:
|
30 |
+
tf = max(tl - 1, 1) # font thickness
|
31 |
+
t_size = cv2.getTextSize(label, 0, fontScale=tl / 3, thickness=tf)[0]
|
32 |
+
c2 = c1[0] + t_size[0], c1[1] - t_size[1] - 3
|
33 |
+
cv2.rectangle(img, c1, c2, color, -1, cv2.LINE_AA) # filled
|
34 |
+
cv2.putText(img, label, (c1[0], c1[1] - 2), 0, tl / 3, [225, 255, 255], thickness=tf, lineType=cv2.LINE_AA)
|
35 |
+
|
36 |
+
|
37 |
def detect(opt, save_img=False):
|
38 |
# from models.experimental import attempt_load
|
39 |
# from utils.datasets import LoadStreams, LoadImages
|
|
|
48 |
scale_coords, xyxy2xywh, strip_optimizer, set_logging, increment_path
|
49 |
from yolov7_package.utils.torch_utils import select_device, load_classifier, time_synchronized, TracedModel
|
50 |
from yolov7_package.utils.datasets import LoadStreams, LoadImages
|
|
|
51 |
|
52 |
bbox = {}
|
53 |
source, weights, view_img, save_txt, imgsz, trace = opt.source, opt.weights, opt.view_img, opt.save_txt, opt.img_size, not opt.no_trace
|