#ifndef ANSSAM_H #define ANSSAM_H #pragma once #include "ANSEngineCommon.h" #include #include #include #include namespace ANSCENTER { class ANSENGINE_API ANSSAM: public ANSODBase { protected: std::string _modelFilePath; public: virtual bool Initialize(std::string licenseKey, ModelConfig modelConfig, const std::string& modelZipFilePath, const std::string& modelZipPassword, std::string& labelMap) override; virtual bool LoadModel(const std::string& modelZipFilePath, const std::string& modelZipPassword) override; virtual bool LoadModelFromFolder(std::string licenseKey, ModelConfig modelConfig, std::string modelName, std::string className, const std::string& modelFolder, std::string& labelMap)override; virtual bool OptimizeModel(bool fp16, std::string& optimizedModelFolder); std::vector RunInference(const cv::Mat& input); std::vector RunInference(const cv::Mat& input, const std::string& camera_id); bool Destroy(); ~ANSSAM(); private: bool Init(const std::string& xml_path, float conf, float iou, bool useGpu); void Infer(const std::string& image_path); cv::Mat Infer(const cv::Mat& image); std::vector Postprocess(const cv::Mat& oriImage); cv::Mat BuildOutput0(); cv::Mat BuildOutput1(); void ScaleBoxes(cv::Mat& box, const cv::Size& oriSize); std::vector ProcessMaskNative(const cv::Mat& oriImage, cv::Mat& protos, cv::Mat& masks_in, cv::Mat& bboxes, cv::Size shape); std::vector NMS(cv::Mat& prediction, int max_det = 300); void xywh2xyxy(cv::Mat& box); ov::Tensor Preprocess(cv::Mat& image); bool ConvertSize(cv::Mat& image); bool ConvertLayout(cv::Mat& image); ov::Tensor BuildTensor(); bool ParseArgs(); bool BuildProcessor(); bool IsGpuAvaliable(const ov::Core& core); cv::Scalar RandomColor(); cv::Mat ConvertToBinary(cv::Mat src); std::string MaskToPolygons(const cv::Mat& image, cv::Rect& boundingBox, std::vector& polygon); cv::Mat Render(const cv::Mat& image, const std::vector& vremat); private: std::shared_ptr m_model; ov::CompiledModel m_compiled_model; ov::Core m_core; ov::InferRequest m_request; std::shared_ptr m_ppp; float m_conf; float m_iou; std::vector input_data; int input_width = 0; int input_height = 0; int input_channel = 3; ov::Shape model_input_shape; ov::Shape model_output0_shape; ov::Shape model_output1_shape; float ratio = 1.0f; float dw = 0.f; float dh = 0.f; int mw = 160; int mh = 160; cv::Mat m_image; }; } #endif