/* // Line.h: interface for the C_Line class. */ #if !defined(ONNX_RUNTIME_DETECTOR_H) #define ONNX_RUNTIME_DETECTOR_H # pragma once #include #include #include #include #include #include #include #ifdef ANSLPR_USE_CUDA #include #endif //ANSLPR_USE_CUDA #include "utils_alpr_detect.h" class OnnxDetector { public: /*** * @brief constructor * @param model_path - path of the TorchScript weight file */ OnnxDetector(Ort::Env& env, const void* model_data, size_t model_data_length, const Ort::SessionOptions& options); OnnxDetector(Ort::Env& env, const ORTCHAR_T* model_path, const Ort::SessionOptions& options); void dump() const; /*** * @brief inference module * @param img - input image * @param conf_threshold - confidence threshold * @param iou_threshold - IoU threshold for nms * @return detection result - bounding box, score, class index */ std::vector> Run(const cv::Mat& img, float conf_threshold, float iou_threshold, bool preserve_aspect_ratio); /*** * @brief inference module * @param img - input image * @param conf_threshold - confidence threshold * @param iou_threshold - IoU threshold for nms * @return detection result - bounding box, score, class index */ std::list>> Run(const cv::Mat& img, float iou_threshold); /*** * @brief * @return the maximum size of input image (ie width or height of dnn input layer) */ int64_t max_image_size() const; bool is_valid() const { return (session.GetInputCount() > 0 && session.GetOutputCount() > 0); } protected: //session options are created outside the class. The classifier access to its options through a constant reference const Ort::SessionOptions & sessionOptions; Ort::Session session; //ONNX environment are created outside the class. The classifier access to its envirponment through a constant reference const Ort::Env& env; }; //non max suppession algorithm to select boxes void nms(const std::vector& srcRects, std::vector& resRects, std::vector& resIndexs, float thresh); //standard scalar product template T vectorProduct(const std::vector& v) { return std::accumulate(v.begin(), v.end(), 1, std::multiplies()); } #endif // !defined(ONNX_RUNTIME_DETECTOR_H)