Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -61,8 +61,8 @@ def detect(img,model):
|
|
61 |
#('rtsp://', 'rtmp://', 'http://', 'https://'))
|
62 |
#print(webcam)
|
63 |
# Directories
|
64 |
-
save_dir = Path(increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok)) # increment run
|
65 |
-
(save_dir / 'labels' if save_txt else save_dir).mkdir(parents=True, exist_ok=True) # make dir
|
66 |
|
67 |
# Initialize
|
68 |
#set_logging()
|
@@ -242,8 +242,8 @@ def detect(img,model):
|
|
242 |
p, s, im0, frame = path, '', im0s, getattr(dataset, 'frame', 0)
|
243 |
|
244 |
p = Path(p) # to Path
|
245 |
-
save_path = str(save_dir / p.name) # img.jpg
|
246 |
-
txt_path = str(save_dir / 'labels' / p.stem) + ('' if dataset.mode == 'image' else f'_{frame}') # img.txt
|
247 |
s += '%gx%g ' % img.shape[2:] # print string
|
248 |
gn = torch.tensor(im0.shape)[[1, 0, 1, 0]] # normalization gain whwh
|
249 |
if len(det):
|
@@ -260,8 +260,7 @@ def detect(img,model):
|
|
260 |
if save_txt: # Write to file
|
261 |
xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
|
262 |
line = (cls, *xywh, conf) if opt.save_conf else (cls, *xywh) # label format
|
263 |
-
|
264 |
-
f.write(('%g ' * len(line)).rstrip() % line + '\n')
|
265 |
|
266 |
if save_img : # Add bbox to image
|
267 |
plot_one_box(xyxy, im0, line_thickness=3)
|
@@ -270,27 +269,7 @@ def detect(img,model):
|
|
270 |
print(f'{s}Done. ({t2 - t1:.3f}s)')
|
271 |
show_seg_result(im0, (da_seg_mask,ll_seg_mask), is_demo=True)
|
272 |
|
273 |
-
|
274 |
-
if save_img:
|
275 |
-
if dataset.mode == 'image':
|
276 |
-
cv2.imwrite(save_path, im0)
|
277 |
-
print(f" The image with the result is saved in: {save_path}")
|
278 |
-
else: # 'video' or 'stream'
|
279 |
-
if vid_path != save_path: # new video
|
280 |
-
vid_path = save_path
|
281 |
-
if isinstance(vid_writer, cv2.VideoWriter):
|
282 |
-
vid_writer.release() # release previous video writer
|
283 |
-
if vid_cap: # video
|
284 |
-
fps = vid_cap.get(cv2.CAP_PROP_FPS)
|
285 |
-
#w = int(vid_cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
286 |
-
#h = int(vid_cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
287 |
-
w,h = im0.shape[1], im0.shape[0]
|
288 |
-
else: # stream
|
289 |
-
fps, w, h = 30, im0.shape[1], im0.shape[0]
|
290 |
-
save_path += '.mp4'
|
291 |
-
vid_writer = cv2.VideoWriter(save_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (w, h))
|
292 |
-
vid_writer.write(im0)
|
293 |
-
|
294 |
#inf_time.update(t2-t1,img.size(0))
|
295 |
#nms_time.update(t4-t3,img.size(0))
|
296 |
#waste_time.update(tw2-tw1,img.size(0))
|
|
|
61 |
#('rtsp://', 'rtmp://', 'http://', 'https://'))
|
62 |
#print(webcam)
|
63 |
# Directories
|
64 |
+
#save_dir = Path(increment_path(Path(opt.project) / opt.name, exist_ok=opt.exist_ok)) # increment run
|
65 |
+
#(save_dir / 'labels' if save_txt else save_dir).mkdir(parents=True, exist_ok=True) # make dir
|
66 |
|
67 |
# Initialize
|
68 |
#set_logging()
|
|
|
242 |
p, s, im0, frame = path, '', im0s, getattr(dataset, 'frame', 0)
|
243 |
|
244 |
p = Path(p) # to Path
|
245 |
+
#save_path = str(save_dir / p.name) # img.jpg
|
246 |
+
#txt_path = str(save_dir / 'labels' / p.stem) + ('' if dataset.mode == 'image' else f'_{frame}') # img.txt
|
247 |
s += '%gx%g ' % img.shape[2:] # print string
|
248 |
gn = torch.tensor(im0.shape)[[1, 0, 1, 0]] # normalization gain whwh
|
249 |
if len(det):
|
|
|
260 |
if save_txt: # Write to file
|
261 |
xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist() # normalized xywh
|
262 |
line = (cls, *xywh, conf) if opt.save_conf else (cls, *xywh) # label format
|
263 |
+
|
|
|
264 |
|
265 |
if save_img : # Add bbox to image
|
266 |
plot_one_box(xyxy, im0, line_thickness=3)
|
|
|
269 |
print(f'{s}Done. ({t2 - t1:.3f}s)')
|
270 |
show_seg_result(im0, (da_seg_mask,ll_seg_mask), is_demo=True)
|
271 |
|
272 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
273 |
#inf_time.update(t2-t1,img.size(0))
|
274 |
#nms_time.update(t4-t3,img.size(0))
|
275 |
#waste_time.update(tw2-tw1,img.size(0))
|