Add YOLOv8 OpenVINO C++ Inference example (#13839)
Co-authored-by: Muhammad Amir Abdurrozaq <m.amir.hs19@gmail.com> Co-authored-by: UltralyticsAssistant <web@ultralytics.com> Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
parent
e30b7c24f2
commit
fb6d8c0123
5 changed files with 365 additions and 0 deletions
41
examples/YOLOv8-OpenVINO-CPP-Inference/main.cc
Normal file
41
examples/YOLOv8-OpenVINO-CPP-Inference/main.cc
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#include "inference.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <opencv2/highgui.hpp>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// Check if the correct number of arguments is provided
|
||||
if (argc != 3) {
|
||||
std::cerr << "usage: " << argv[0] << " <model_path> <image_path>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Get the model and image paths from the command-line arguments
|
||||
const std::string model_path = argv[1];
|
||||
const std::string image_path = argv[2];
|
||||
|
||||
// Read the input image
|
||||
cv::Mat image = cv::imread(image_path);
|
||||
|
||||
// Check if the image was successfully loaded
|
||||
if (image.empty()) {
|
||||
std::cerr << "ERROR: image is empty" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Define the confidence and NMS thresholds
|
||||
const float confidence_threshold = 0.5;
|
||||
const float NMS_threshold = 0.5;
|
||||
|
||||
// Initialize the YOLO inference with the specified model and parameters
|
||||
yolo::Inference inference(model_path, cv::Size(640, 640), confidence_threshold, NMS_threshold);
|
||||
|
||||
// Run inference on the input image
|
||||
inference.RunInference(image);
|
||||
|
||||
// Display the image with the detections
|
||||
cv::imshow("image", image);
|
||||
cv::waitKey(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue