47 lines
1.2 KiB
C++
47 lines
1.2 KiB
C++
|
#ifndef INFER_HPP_
|
||
|
#define INFER_HPP_
|
||
|
|
||
|
#include <opencv2/dnn/dnn.hpp>
|
||
|
#include <opencv2/highgui/highgui.hpp>
|
||
|
#include <opencv2/imgproc/imgproc.hpp>
|
||
|
#include <opencv2/opencv.hpp>
|
||
|
#include <openvino/openvino.hpp>
|
||
|
|
||
|
// Структура обнаружения
|
||
|
struct Detection {
|
||
|
short class_id; // Идентификатор класс
|
||
|
float probability; // Вероятность обнаружения
|
||
|
cv::Rect box; // Размеры объекта
|
||
|
};
|
||
|
|
||
|
// Класс обнаружения
|
||
|
class Inf {
|
||
|
public:
|
||
|
Inf() {};
|
||
|
Inf(const std::string &model_path, const float &model_probability, const float &model_NMS);
|
||
|
Inf(const std::string &model_path, const cv::Size model_input_shape, const float &model_probability, const float &model_NMS);
|
||
|
~Inf() {};
|
||
|
|
||
|
void inference(cv::Mat &frame);
|
||
|
|
||
|
private:
|
||
|
void init(const std::string &model_path);
|
||
|
void pre(const cv::Mat &frame);
|
||
|
void post( cv::Mat &frame);
|
||
|
cv::Rect GetBoundingBox(const cv::Rect &src) const;
|
||
|
void DrawDetectedObject(cv::Mat &frame, const Detection &detections) const;
|
||
|
|
||
|
cv::Point2f scale_factor;
|
||
|
|
||
|
cv::Size2f input_shape;
|
||
|
cv::Size output_shape;
|
||
|
|
||
|
ov::InferRequest inference_request;
|
||
|
ov::CompiledModel compiled_model;
|
||
|
|
||
|
float probability;
|
||
|
float NMS;
|
||
|
};
|
||
|
|
||
|
#endif // INFER_HPP_
|