Closed nakornsoft closed 4 years ago
Hi, Were you able run this repo on a video ??
I just want to run a simple video on this but..
after I updated this self.vdo = cv2.VideoCapture('MyVideo.avi')
and it still ask me for VIDEO_PATH
@crazylazydboy
for run code python demo_yolo3_deepsort.py demo.mp4
Thanks @nakhonsoft , but I went the other way and commented every code with VIDEO_PATH
gave my link manually to
self.vdo = cv2.VideoCapture('MyVideo.avi')
it works anyway..
@crazylazydboy
import os import cv2 import time import argparse import numpy as np
from YOLOv3 import YOLOv3 from deep_sort import DeepSort from util import COLORS_10, draw_bboxes
class Detector(object): def init(self, args): self.args = args if args.display: cv2.namedWindow("test", cv2.WINDOW_NORMAL) cv2.resizeWindow("test", args.display_width, args.display_height)
self.vdo = cv2.VideoCapture()
self.yolo3 = YOLOv3(args.yolo_cfg, args.yolo_weights, args.yolo_names, is_xywh=True, conf_thresh=args.conf_thresh, nms_thresh=args.nms_thresh)
self.deepsort = DeepSort(args.deepsort_checkpoint)
self.class_names = self.yolo3.class_names
def __enter__(self):
self.vdo.open("test.mp4")
self.im_width = int(self.vdo.get(cv2.CAP_PROP_FRAME_WIDTH))
self.im_height = int(self.vdo.get(cv2.CAP_PROP_FRAME_HEIGHT))
if self.args.save_path:
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
self.output = cv2.VideoWriter(self.args.save_path, fourcc, 20, (self.im_width,self.im_height))
assert self.vdo.isOpened()
return self
def __exit__(self, exc_type, exc_value, exc_traceback):
if exc_type:
print(exc_type, exc_value, exc_traceback)
def detect(self):
while self.vdo.grab():
start = time.time()
_, ori_im = self.vdo.retrieve()
im = cv2.cvtColor(ori_im, cv2.COLOR_BGR2RGB)
im = ori_im
bbox_xcycwh, cls_conf, cls_ids = self.yolo3(im)
if bbox_xcycwh is not None:
# select class person
mask = cls_ids==0
bbox_xcycwh = bbox_xcycwh[mask]
bbox_xcycwh[:,3:] *= 1.2
cls_conf = cls_conf[mask]
outputs = self.deepsort.update(bbox_xcycwh, cls_conf, im)
if len(outputs) > 0:
bbox_xyxy = outputs[:,:4]
identities = outputs[:,-1]
ori_im = draw_bboxes(ori_im, bbox_xyxy, identities)
end = time.time()
print("time: {}s, fps: {}".format(end-start, 1/(end-start)))
if self.args.display:
cv2.imshow("test", ori_im)
cv2.waitKey(1)
if self.args.save_path:
self.output.write(ori_im)
def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("--yolo_cfg", type=str, default="YOLOv3/cfg/yolo_v3.cfg") parser.add_argument("--yolo_weights", type=str, default="YOLOv3/yolov3.weights") parser.add_argument("--yolo_names", type=str, default="YOLOv3/cfg/coco.names") parser.add_argument("--conf_thresh", type=float, default=0.5) parser.add_argument("--nms_thresh", type=float, default=0.4) parser.add_argument("--deepsort_checkpoint", type=str, default="deep_sort/deep/checkpoint/ckpt.t7") parser.add_argument("--max_dist", type=float, default=0.2) parser.add_argument("--ignore_display", dest="display", action="store_false") parser.add_argument("--display_width", type=int, default=800) parser.add_argument("--display_height", type=int, default=600) parser.add_argument("--save_path", type=str, default="demo.avi") return parser.parse_args()
if name=="main": args = parse_args() with Detector(args) as det: det.detect()
def enter(self):
self.vdo.open("test.mp4")
self.im_width = int(self.vdo.get(cv2.CAP_PROP_FRAME_WIDTH))
self.im_height = int(self.vdo.get(cv2.CAP_PROP_FRAME_HEIGHT))
parser.add_argument("VIDEO_PATH", type=str)
Hi, @nakhonsoft Have you tried using train.py.. ? I am trying to use it. But I get the following error.
Segmentation fault (core dumped)
Do you have any idea why ??
no, so now i stoped project i developing face recognition
next year i will develop this project continue
i have project same amazon-go
Hi, Don't worry.. I found the error. The issue was in the matplotlib.pyplot
version. I had the latest version which was 3.1.2 I uninstalled it and installed an older version 2.0.0 It works now..
Before I try this, whats the speed you're getting on single and multiple cameras/videos @crazylazydboy ?
@zubairahmed-ai Depends on your environment.. Basically, 7-9 FPS @ 1080p & 11-13 FPS @ 720p (running on a 1080Ti GPU)
Thanks for the reply, I am getting that kinda FPS from this so was looking to switch to PyTorch only if it gives me better FPS, I guess I should try changing that to MobileNetV3 and see what happens
@zubairahmed-ai Have a try. But I highly doubt, it will be better than this. You can also try reducing resolution below 720p, if you want more speed.
@nakhonsoft did you get to run this on multiple cameras?
help me please! i need make detection person multiple cameras
how to do it?