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

Add support for image, video, and webcam sources with GPU/CPU selection for ONNX model inference #101

Merged
merged 2 commits into from
Dec 4, 2024

Conversation

sctrueew
Copy link

@sctrueew sctrueew commented Dec 3, 2024

This pull request introduces flexibility to the ONNX inference application by allowing users to specify different types of sources for processing images, videos, or webcam inputs. The user can also select between GPU and CPU execution through command-line arguments. The main updates include:

  • Support for multiple sources: The program can now process images, video files, or live webcam streams based on user input.
  • Dynamic GPU/CPU selection: Users can specify whether to run the model inference on the CPU or GPU using command-line arguments.
  • Improved source handling: The program dynamically detects whether the source is a webcam, a video file, or an image file, and handles each case appropriately.
  • FPS calculation for video/webcam: The program calculates and displays the FPS (frames per second) during video or webcam processing.

Command-Line Arguments:

  • modelPath: The path to the ONNX model file.
  • source: The source to process, which can be either an image file, a video file, or the keyword webcam for live webcam feed.
  • useGPU: A flag to specify whether to use the GPU (1 for GPU, 0 for CPU).

Processing Flow:

  • The program reads the input source based on the command-line argument source and processes it accordingly.
  • It handles images using cv::imread, video files with cv::VideoCapture, and webcam input using cv::VideoCapture(0).

Performance:

  • The program shows real-time FPS for video and webcam processing, providing performance feedback.

How to Test:
To test the functionality, compile the program and run it with different sources (image, video, webcam) and GPU/CPU options as described below.

Usage:
./onnx_example <modelPath> <source[imagePath|videoPath|webcam]> <useGPU[1/0]>

Example 1: Process an Image with GPU:
./onnx_example "dfine_n_coco.onnx" "sample.jpg" 1

Example 2: Process a Video File with CPU:
./onnx_example "dfine_n_coco.onnx" "sample.MP4" 0

Example 3: Use Webcam for Real-Time Processing with GPU:
./onnx_example "dfine_n_coco.onnx" "webcam" 1

Additional Information:

  • Dynamic Source Handling: The program automatically detects whether the source is a video file, image file, or webcam feed and processes accordingly.
  • GPU/CPU Handling: The program supports both CPU and GPU execution. When using the GPU, OrtCUDAProviderOptions is configured to use the first CUDA device (device ID = 0).
  • Real-Time FPS: For video or webcam sources, the program calculates the FPS and outputs it every second to monitor performance.

@Peterande Peterande merged commit 39b7c46 into Peterande:master Dec 4, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants