tensorturtle / classy-sort-yolov5

Ready-to-use realtime multi-object tracker that works for any object category. YOLOv5 + SORT implementation.
GNU General Public License v3.0
110 stars 29 forks source link

Saving video output does not work. #10

Closed mattdoescode closed 2 years ago

mattdoescode commented 2 years ago

Setting --save-img to true when processing a webcam input causes :

Traceback (most recent call last): File "classy_track.py", line 318, in detect(args) File "classy_track.py", line 256, in detect fps = vid_cap.get(cv2.CAP_PROP_FPS) AttributeError: 'NoneType' object has no attribute 'get'

tensorturtle commented 2 years ago

Are you having a problem only when --save-img? Are you able to see the inference result with --view-img?

mattdoescode commented 2 years ago

Only having the problem with --save-img. I am able to view the video feed with --view-img for 1 frame and then the program crashes (works just fine when not using save-img).

tensorturtle commented 2 years ago

Could you tell me exactly what path you set as the --save-img path?

Please see this article for more debugging possibilities.

mattdoescode commented 2 years ago

I've been setting it is to "True". The save path is "inference\output". I'll look into the article. thank you!

The bug seems to come from this line: _for frame_idx, (path, img, im0s, vidcap) in enumerate(dataset): In class Loadstreams cap = cv2.VideoCapture(eval(s) if s.isnumeric() else s) works just fine. But when we try to enumerate it when it breaks.

tensorturtle commented 2 years ago

I'm still not sure why this bug only happens when --save-img is True, but if the problem is with cv2.VideoCapture, then try running the basic OpenCV webcam test script from this link.

Also, it could be helpful if you cold tell me all the details about what computer / camera you're using.

mattdoescode commented 2 years ago

I'm pretty sure I've figured it out. I'll post the solution tomorrow. Thank you so much for the help here!

tensorturtle commented 2 years ago

Very glad to hear. Thank you.

mattdoescode commented 2 years ago

Got it... and I feel really silly (I'm a novice programmer). The video recorder was never being passed back.

In datasets.py line 324-> return img_path, img, img0, None. I changed None to be self.cap and added a newline on line 280 self.cap = cap

This might break some aspects of the script but for my usage, it works. I'll play with this and eventually make a pull request.