Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I save the live video stream with detected objects? #2596

Closed
ghost opened this issue Mar 25, 2021 · 2 comments · Fixed by #2598
Closed

How do I save the live video stream with detected objects? #2596

ghost opened this issue Mar 25, 2021 · 2 comments · Fixed by #2598
Labels
question Further information is requested

Comments

@ghost
Copy link

ghost commented Mar 25, 2021

❔Question

Hi,

I would save the live video stream after detection. How can i do it?
Because I would do the discovery overnight and watch it the next day.

It would also be nice to have a picture taken during the live stream and saved as soon as an object is detected.

@ghost ghost added the question Further information is requested label Mar 25, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Mar 25, 2021

👋 Hello @cyberFoxi, thank you for your interest in 🚀 YOLOv5! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide screenshots and minimum viable code to reproduce your issue, otherwise we can not help you.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset images, training logs, screenshots, and a public link to online W&B logging if available.

For business inquiries or professional support requests please visit https://www.ultralytics.com or email Glenn Jocher at glenn.jocher@ultralytics.com.

Requirements

Python 3.8 or later with all requirements.txt dependencies installed, including torch>=1.7. To install run:

$ pip install -r requirements.txt

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

CI CPU testing

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training (train.py), testing (test.py), inference (detect.py) and export (export.py) on MacOS, Windows, and Ubuntu every 24 hours and on every commit.

@glenn-jocher glenn-jocher linked a pull request Mar 25, 2021 that will close this issue
@glenn-jocher
Copy link
Member

@cyberFoxi I've created a PR 2598 to address this issue. webcam and streaming sources will now automatically be saved just like images and videos by detect.py.

Also saving can now be disabled for all sources with the new --nosave argument:

python detect.py --nosave

This PR should be merged soon and then you should be able to customize it around L123-L140 to only write frames when detections are present to solve your problem. Good luck.

            # Save results (image with detections)
            if save_img:
                if dataset.mode == 'image':
                    cv2.imwrite(save_path, im0)
                else:  # 'video' or 'stream'
                    if vid_path != save_path:  # new video
                        vid_path = save_path
                        if isinstance(vid_writer, cv2.VideoWriter):
                            vid_writer.release()  # release previous video writer
                        if vid_cap:  # video
                            fps = vid_cap.get(cv2.CAP_PROP_FPS)
                            w = int(vid_cap.get(cv2.CAP_PROP_FRAME_WIDTH))
                            h = int(vid_cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
                        else:  # stream
                            fps, w, h = 30, im0.shape[1], im0.shape[0]
                            save_path += '.mp4'
                        vid_writer = cv2.VideoWriter(save_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (w, h))
                    vid_writer.write(im0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant