Untitled
unknown
plain_text
a year ago
2.2 kB
5
Indexable
#include <iostream>
#include<opencv2/opencv.hpp>
#include<math.h>
#include "yolov8_onnx.h"
#include "yolov8_onnx._1.h"
#include "yolov8_utils_1.h"
#include<time.h>
using namespace std;
using namespace cv;
using namespace dnn;
template<typename _Tp>
int yolov8_onnx(_Tp& task, Mat& img, string& model_path, string& img_name)
{
if (task.ReadModel(model_path, false))
{
cout << "read net ok!" << endl;
}
else
{
return -1;
}
cv::Scalar color(0,255,255);
vector<OutputParams> result;
std::string outputFolder = "/home/simran/yolo_v8_inference 2/yolo_v8_inference/out/";
if (task.OnnxDetect(img, result))
{
DrawPred(img, result, task._className, color);
//imwrite("result.jpg",img);
cv::imwrite(outputFolder + "/" + img_name + ".jpg", img);
}
else
{
cout << "Detect Failed!" << endl;
}
return 0;
}
int main()
{
std::string inputFolder1 = "/home/simran/Desktop/Data/";
std::vector<std::string> files1;
cv::glob(inputFolder1, files1);
if (files1.empty()) {
std::cerr << "folder must contain images." << std::endl;
}
for (size_t i = 0; i < files1.size(); i++)
{
// Load the images using OpenCV
cv::Mat src = cv::imread(files1[i]);
if (src.empty())
{
std::cout << "Failed to load the image." << std::endl;
return -1;
}
std::string filename = files1[i];
std::cout<<"file :"<<filename<<std::endl;
size_t last_slash = filename.find_last_of('/');
size_t last_dot = filename.find_last_of('.');
std::string img_name = filename.substr(last_slash + 1, last_dot - last_slash - 1);
//string img_path = "/home/teuser/Documents/v8_inference/yolov8-opencv-onnxruntime-cpp/images/CLHU479358-40-CN-4.jpg";
string model_path_detect = "/home/simran/yolo_v8_inference 2/yolo_v8_inference/models/best_10k.onnx";
//Mat src = imread(img_path);
Mat img = src.clone();
Yolov8Onnx task_detect_ort;
yolov8_onnx(task_detect_ort,img,model_path_detect,img_name); //yoolov8 onnxruntime detect
}
return 0;
}
Editor is loading...
Leave a Comment