Untitled
unknown
plain_text
a year ago
1.2 kB
4
Indexable
yolov8_infer.h
-----------------
#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>
std::vector<std::tuple<int, float, cv::Rect>> DetectObject(_Tp& task, Mat& img, string& model_path, vector<OutputParams>& result){
bool model_loaded = task.ReadModel(model_path, false);
if (model_loaded)
{
cout << "read net ok!" << endl;
}
else
{
std::cout<<"can't read net"<<std::endl;
}
bool detections_found = task.OnnxDetect(img, result);
int detections_count = result.size();
std::vector<std::tuple<int, float, cv::Rect>> detections;
if (detections_count > 0)
{
for (int i = 0; i < detections_count; ++i)
{
auto detection = result[i];
int class_id = detection.id;
float confidence = detection.confidence;
cv::Rect box = detection.box;
detections.push_back(std::make_tuple(class_id, confidence, box));
}
}
return detections;
}
Editor is loading...
Leave a Comment