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 to display real-time MP4 processing results #11485

Open
1 task done
hnulmz3 opened this issue May 4, 2023 · 43 comments
Open
1 task done

How to display real-time MP4 processing results #11485

hnulmz3 opened this issue May 4, 2023 · 43 comments
Labels
question Further information is requested

Comments

@hnulmz3
Copy link

hnulmz3 commented May 4, 2023

Search before asking

Question

Using decect.py to test MP4 video has only one result output and an intermediate 'Video 1/1 (469/486).......... 640x384 (no detections), text display of 80.6ms', what should I do if I want to display the video in real time?

Additional

Sorry, I'm a green hand

@hnulmz3 hnulmz3 added the question Further information is requested label May 4, 2023
@github-actions
Copy link
Contributor

github-actions bot commented May 4, 2023

👋 Hello @hnulmz3, 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 a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Requirements

Python>=3.7.0 with all requirements.txt installed including PyTorch>=1.7. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

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

YOLOv5 CI

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

Introducing YOLOv8 🚀

We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 🚀!

Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects.

Check out our YOLOv8 Docs for details and get started with:

pip install ultralytics

@hnulmz3
Copy link
Author

hnulmz3 commented May 4, 2023 via email

@hnulmz3
Copy link
Author

hnulmz3 commented May 4, 2023

OK,i got it by myself

@glenn-jocher
Copy link
Member

@hnulmz3 that's great to hear! Don't hesitate to reach out if you have any further questions or if there's anything we can assist you with in the future. Have a great day!

@github-actions
Copy link
Contributor

github-actions bot commented Jun 4, 2023

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label Jun 4, 2023
@hnulmz3
Copy link
Author

hnulmz3 commented Jun 4, 2023 via email

@glenn-jocher
Copy link
Member

@hnulmz3 太好了,很高兴您已经解决了问题!如果将来还有任何问题或需要我们的帮助,请随时告诉我们。祝您拥有愉快的一天!

@github-actions github-actions bot removed the Stale label Jun 5, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jul 5, 2023

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label Jul 5, 2023
@hnulmz3
Copy link
Author

hnulmz3 commented Jul 5, 2023 via email

@glenn-jocher
Copy link
Member

@hnulmz3 感谢您的反馈!如果将来还有任何问题或需要我们的帮助,请随时告诉我们。祝您拥有愉快的一天!

@github-actions github-actions bot removed the Stale label Jul 6, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 6, 2023

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label Aug 6, 2023
@hnulmz3
Copy link
Author

hnulmz3 commented Aug 6, 2023 via email

@glenn-jocher
Copy link
Member

@hnulmz3 you're welcome! If you have any other questions or need further assistance, feel free to ask.

@github-actions github-actions bot removed the Stale label Aug 7, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 7, 2023

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label Sep 7, 2023
@hnulmz3
Copy link
Author

hnulmz3 commented Sep 7, 2023 via email

@glenn-jocher
Copy link
Member

@hnulmz3 您好!非常感谢您的反馈!如果您有任何其他问题或需要进一步的帮助,请随时告知我们。祝您使用 YOLOv5 的愉快!

@github-actions github-actions bot removed the Stale label Sep 8, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Oct 8, 2023

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label Oct 8, 2023
@hnulmz3
Copy link
Author

hnulmz3 commented Oct 8, 2023 via email

@glenn-jocher
Copy link
Member

@hnulmz3 你好!

感谢你的反馈!如果你还有其他问题或需要进一步的帮助,请随时告诉我们。我们团队一直致力于提供高质量的支持和解决方案。祝你使用 YOLOv5 愉快!

最好的祝愿!

@github-actions github-actions bot removed the Stale label Oct 9, 2023
Copy link
Contributor

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label Jan 11, 2024
@hnulmz3
Copy link
Author

hnulmz3 commented Jan 11, 2024 via email

@glenn-jocher
Copy link
Member

@hnulmz3 不客气!如果将来需要帮助,随时欢迎回来。祝您一切顺利! 😊👍

@github-actions github-actions bot removed the Stale label Jan 12, 2024
Copy link
Contributor

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label Feb 11, 2024
@hnulmz3
Copy link
Author

hnulmz3 commented Feb 11, 2024 via email

@glenn-jocher
Copy link
Member

@hnulmz3 很好!如果您有其他问题或需要进一步的帮助,请随时告知。祝您使用YOLOv5愉快!🌟

@github-actions github-actions bot removed the Stale label Feb 12, 2024
Copy link
Contributor

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label Mar 14, 2024
@hnulmz3
Copy link
Author

hnulmz3 commented Mar 14, 2024 via email

@glenn-jocher
Copy link
Member

@hnulmz3 you're welcome! If you have more questions or need further assistance in the future, feel free to reach out. Happy coding with YOLOv5! 😊🚀

@github-actions github-actions bot removed the Stale label Mar 15, 2024
Copy link
Contributor

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label Apr 14, 2024
@hnulmz3
Copy link
Author

hnulmz3 commented Apr 14, 2024 via email

@glenn-jocher
Copy link
Member

You're welcome! If you have any more questions or need assistance, just let us know. Happy to help! 😊

@github-actions github-actions bot removed the Stale label Apr 15, 2024
Copy link
Contributor

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label May 16, 2024
@hnulmz3
Copy link
Author

hnulmz3 commented May 16, 2024 via email

@glenn-jocher
Copy link
Member

You're welcome! If there's anything else you need help with, just let me know. Happy coding! 😊

@github-actions github-actions bot removed the Stale label May 17, 2024
Copy link
Contributor

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label Jun 16, 2024
@hnulmz3
Copy link
Author

hnulmz3 commented Jun 16, 2024 via email

@glenn-jocher
Copy link
Member

Hello @hnulmz3,

Thank you for reaching out! If you want to display real-time processing results while testing an MP4 video using detect.py, you can modify the script to show the video frames with detections as they are processed.

Here's a step-by-step guide to help you achieve this:

  1. Ensure you have the latest version: Make sure you are using the most recent versions of torch and YOLOv5. You can update YOLOv5 by running:

    git pull
    pip install -U -r requirements.txt
  2. Modify detect.py: You can add code to display each frame with OpenCV. Below is an example modification to detect.py:

    import cv2
    from pathlib import Path
    import torch
    from models.common import DetectMultiBackend
    from utils.datasets import LoadStreams, LoadImages
    from utils.general import check_img_size, non_max_suppression, scale_coords, xyxy2xywh, strip_optimizer, set_logging, increment_path
    from utils.plots import plot_one_box
    from utils.torch_utils import select_device, load_classifier, time_synchronized
    
    # Initialize
    set_logging()
    device = select_device('')
    half = device.type != 'cpu'  # half precision only supported on CUDA
    
    # Load model
    model = DetectMultiBackend(weights, device=device, dnn=dnn)
    stride, names, pt = model.stride, model.names, model.pt
    imgsz = check_img_size(imgsz, s=stride)  # check image size
    
    # Dataloader
    dataset = LoadImages(source, img_size=imgsz, stride=stride, auto=pt)
    bs = 1  # batch_size
    
    # Run inference
    model.warmup(imgsz=(1 if pt else bs, 3, *imgsz))  # warmup
    seen, dt = 0, [0.0, 0.0, 0.0]
    for path, img, im0s, vid_cap in dataset:
        img = torch.from_numpy(img).to(device)
        img = img.half() if half else img.float()  # uint8 to fp16/32
        img /= 255.0  # 0 - 255 to 0.0 - 1.0
        if img.ndimension() == 3:
            img = img.unsqueeze(0)
    
        # Inference
        t1 = time_synchronized()
        pred = model(img, augment=augment, visualize=visualize)
        t2 = time_synchronized()
    
        # NMS
        pred = non_max_suppression(pred, conf_thres, iou_thres, classes, agnostic_nms)
        t3 = time_synchronized()
    
        # Process detections
        for i, det in enumerate(pred):  # detections per image
            seen += 1
            p, s, im0, frame = path, '', im0s.copy(), getattr(dataset, 'frame', 0)
    
            p = Path(p)  # to Path
            save_path = str(save_dir / p.name)  # img.jpg
            txt_path = str(save_dir / 'labels' / p.stem) + ('' if dataset.mode == 'image' else f'_{frame}')  # img.txt
            s += '%gx%g ' % img.shape[2:]  # print string
            gn = torch.tensor(im0.shape)[[1, 0, 1, 0]]  # normalization gain whwh
            imc = im0.copy() if save_crop else im0  # for save_crop
            annotator = Annotator(im0, line_width=line_thickness, example=str(names))
            if len(det):
                # Rescale boxes from img_size to im0 size
                det[:, :4] = scale_coords(img.shape[2:], det[:, :4], im0.shape).round()
    
                # Print results
                for c in det[:, -1].unique():
                    n = (det[:, -1] == c).sum()  # detections per class
                    s += f"{n} {names[int(c)]}{'s' * (n > 1)}, "  # add to string
    
                # Write results
                for *xyxy, conf, cls in reversed(det):
                    if save_txt:  # Write to file
                        xywh = (xyxy2xywh(torch.tensor(xyxy).view(1, 4)) / gn).view(-1).tolist()  # normalized xywh
                        line = (cls, *xywh, conf) if save_conf else (cls, *xywh)  # label format
                        with open(txt_path + '.txt', 'a') as f:
                            f.write(('%g ' * len(line)).rstrip() % line + '\n')
    
                    if save_img or view_img:  # Add bbox to image
                        label = f'{names[int(cls)]} {conf:.2f}'
                        plot_one_box(xyxy, im0, label=label, color=colors[int(cls)], line_thickness=line_thickness)
    
            # Stream results
            if view_img:
                cv2.imshow(str(p), im0)
                if cv2.waitKey(1) == ord('q'):  # q to quit
                    raise StopIteration
    
            # 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 = str(Path(save_path).with_suffix('.mp4'))  # force *.mp4 suffix on results videos
                        vid_writer = cv2.VideoWriter(save_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (w, h))
                    vid_writer.write(im0)
    
    if save_txt or save_img:
        s = f"\n{len(list(save_dir.glob('labels/*.txt')))} labels saved to {save_dir / 'labels'}" if save_txt else ''
        print(f"Results saved to {save_dir}{s}")
    print(f'Done. ({t3 - t0:.3f}s)')
  3. Run the modified script: Execute the modified detect.py script with your video file as the source:

    python detect.py --source path/to/your/video.mp4 --view-img

This modification will display the video frames with detections in real-time. If you encounter any issues or have further questions, feel free to ask!

@github-actions github-actions bot removed the Stale label Jun 17, 2024
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

No branches or pull requests

2 participants