123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- /*
- * @Author: lishengyin lishengyin@sz-sunwin.com
- * @Date: 2022-09-04 20:27:57
- * @LastEditors: lishengyin
- * @LastEditTime: 2022-10-25 11:12:35
- * @FilePath: /gsd_check/plugins/gsd_InferPlugin.h
- * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
- */
- /**
- *
- * gsd_InferPlugin.h
- *
- */
- #pragma once
- #include <drogon/plugins/Plugin.h>
- #include <drogon/HttpController.h>
- #include <drogon/drogon.h>
- #include <chrono>
- #include <cmath>
- #include <opencv2/opencv.hpp>
- #include "Util/logger.h"
- #include "Util/SqlPool.h"
- #include "InferTools.hpp"
- #include <utility>
- #include <future>
- #include <iostream>
- #include <dirent.h>
- #include "Base64.h"
- #include "gsd_CenterGroup.h"
- #include "uuid.hpp"
- //using namespace toolkit;
- namespace gsd
- {
- /**
- * @description: InferTaskType
- * @param {*}
- * @return {*}
- */
- enum class InferPluginTaskType{
- CHECKT_TASK,
- CLASSIFY_TASK
- };
- class InferPlugin : public drogon::Plugin<InferPlugin>
- {
- public:
- InferPlugin() {}
- /// This method must be called by drogon to initialize and start the plugin.
- /// It must be implemented by the user.
- virtual void initAndStart(const Json::Value &config) override;
- /// This method must be called by drogon to shutdown the plugin.
- /// It must be implemented by the user.
- virtual void shutdown() override;
- /**
- * @description: StartTask
- * @return {*}
- */
- virtual void StartTask();
- /**
- * @description: 检查任务
- * @param {Mat&} img 图片
- * @param {CNStreamInferData&} data 前端的推理数据
- * @return {*}
- */
- virtual std::pair<bool, std::string> CheckTask(std::shared_ptr<cv::Mat> img, CNStreamInferData::Ptr data = nullptr);
- /**
- * @description: 获取结果
- * @param {CNStreamInferData&} data1
- * @param {CNStreamInferData&} data2
- * @return {*}
- */
- virtual std::pair<bool, std::string> getInfoResult(std::shared_ptr<cv::Mat> img, CNStreamInferData::Ptr data1, CNStreamInferData::Ptr data2);
- /**
- * @description: CreateTask
- * @return {*}
- */
- virtual std::future<std::pair<bool, std::string>> CreateTask(const drogon::HttpRequestPtr& req, InferPluginTaskType type = InferPluginTaskType::CHECKT_TASK);
- /**
- * @description: GetBboxCorner
- * @param {const InferInfo} object
- * @param {int} img_width
- * @param {int} img_height
- * @return {*}
- */
- static std::pair<cv::Point, cv::Point> GetBboxCorner(const InferInfo object, int img_width, int img_height);
- /**
- * @description: CalcThickness
- * @param {int} image_width
- * @param {float} thickness
- * @return {*}
- */
- static int CalcThickness(int image_width, float thickness);
- /**
- * @description: DrawBox
- * @param {const} cv
- * @param {const} cv
- * @param {const} cv
- * @return {*}
- */
- static void DrawBox(cv::Mat& image, const cv::Point& top_left, const cv::Point& bottom_right, const cv::Scalar color);
- /**
- * @description:释放资源
- * @return {*}
- */
- virtual void Destroy();
- protected:
- // tools
- InferTools::Ptr m_InferTools = nullptr;
- std::shared_ptr<ThreadPool> pool = nullptr;
- bool stop_ = false;
- };
- }
|