Files
handleaiuinew/env/handdleAI/include/handleAI.h
T
2024-05-18 23:53:26 +08:00

288 lines
8.1 KiB
C++

#pragma once
//#define windows
#include <opencv2/core/core.hpp>
#include <stdio.h>
#ifdef _WIN32
#define EXPORT_PKG extern "C" __declspec(dllexport)
#else
#define EXPORT_PKG extern "C"
#endif
#ifdef linux
#include <unistd.h>
#ifndef __declspec
#define __declspec(x)
#endif
#ifndef _stdcall
#define _stdcall
#endif
#ifndef _access
#define _access access
#endif
#define strcat_s(a, b, c) (strcat(a, c))
#define strcpy_s(a, b, c) (strcpy(a, c))
#define strtok_s(a, b, c) (strtok(a, b))
void fopen_s(FILE **pFile, const char *filename, const char *mode);
#endif
namespace handdleAI
{
enum ClsStatus
{
Cls_Undifne = -1,
Cls_Success,
Cls_NG1,
Cls_NG2,
Cls_NG3
};
enum SegStatus
{
Seg_Undifne = -1,
Seg_Success,
Seg_NG1,
Seg_NG2,
Seg_NG3
};
enum OCRStatus
{
OCR_Undifne = -1,
OCR_Success,
OCR_NG1,
OCR_NG2,
OCR_NG3
};
enum DetStatus
{
Det_Undifne = -1,
Det_Success,
Det_NG1,
Det_NG2,
Det_NG3
};
enum OneStatus
{
One_Undifne = -1,
One_Success,
One_NG1,
One_NG2,
One_NG3
};
enum EncodeType
{
Ansi_GBK = 0,
Utf8_Thai
};
typedef struct
{
float x;
float y;
} PointF;
typedef struct
{
float x;
float y;
float w;
float h;
PointF points[4];
float score;
int classes;
} Bbox;
typedef struct
{
float x;
float y;
float w;
float h;
float score;
EncodeType encode;
cv::String rstChar;
} OCRChar; //新添加
typedef struct
{
int x;
int y;
int w;
int h;
int classes;
double area;
cv::Mat resultMask;
} SegResult;
enum CutType
{
RegularRect = 0,
SlantRect = 1,
Contour = 2,
Default = 3
};
typedef struct
{
CutType cutType;
int DstW;
int DstH;
bool fillorresize;
int color;
} CutParam;
using namespace std;
class pSegmentation
{
public:
virtual ~pSegmentation() {}
virtual void Release() = 0;
virtual cv::Mat Evaluate(cv::Mat srcImg) = 0;
virtual cv::Mat Evaluate(const char *imgPath) = 0;
virtual void Evaluate(cv::Mat srcImg, std::vector<SegResult> &result, CutParam param) = 0;
virtual void Evaluate(const char *imgPath, std::vector<SegResult> &result, CutParam param) = 0;
virtual SegStatus getStatus() = 0;
virtual void setStride(float stride) = 0;
const int patchSizeNet = 0;
const int batchSizeNet = 0;
const int maxbatchSizeNet = 0;
const float strideNet = 0.9;
const int m_classes = 0;
const int m_gpuID = 0;
};
EXPORT_PKG pSegmentation *CreateSegObj(char *modelPath, int batchSize = 256, float stride = 0.9, int patchSize = 256, int deviceId = 0, int classes = 2);
EXPORT_PKG pSegmentation *CreateSegObjS(char *modelPath, int batchSize = 256, int deviceId = 0);
EXPORT_PKG pSegmentation *CreateSegObjF(char *modelPath, char *calib, int batchSize = 256, int deviceId = 0);
EXPORT_PKG void DestroySegObj(pSegmentation *pExport);
EXPORT_PKG int GetMaxBatchsize(int gpuId, int width, int height);
EXPORT_PKG float CheckNvidiaDriverVersion();
EXPORT_PKG float GetCurrentCudaLowestVersion();
EXPORT_PKG char *GetCurrentVersion();
//! \deprecated Superseded by Evaluate(cv::Mat srcImg, std::vector<SegResult> &result, CutParam param). Already deprecated in 2.1.11.1
// extern "C" cv::Mat CutImage(cv::Mat src, int CenterX, int CenterY, int &DstW, int &DstH, bool Fill = false, int Color = 0);
// extern "C" cv::Mat CutImageByContour(cv::Mat src, int DstW, int DstH, vector<cv::Point> ContourPt, CutType CutType = CutType::RegularRect, bool Resize = false, int color = 0);
EXPORT_PKG bool IDecode(const char *orifolder, const char *rstfolder);
class pClassification
{
public:
virtual ~pClassification() {}
virtual int Evaluate(cv::Mat srcImg) = 0;
virtual int Evaluate(const char *imgPath) = 0;
virtual int Evaluate(vector<cv::Mat> imgList, vector<int> &rstClassList, vector<float> &rstProbList) = 0;
virtual int Evaluate(const char* imgPath, std::string& resultString) = 0;
virtual float getProbability() = 0;
virtual float *getProbabilityList() = 0;
virtual ClsStatus getStatus() = 0;
virtual void Release() = 0;
const int m_imageWidth = 0;
const int m_imageHeight = 0;
const int m_classNum = 0;
const int m_inGpuID = 0;
};
EXPORT_PKG pClassification *CreateClsObj(char *inputModelPath, char *inputJsonPath, int in_gpuID, int in_width, int in_height, int classNum, int batchsize = 1);
EXPORT_PKG pClassification *CreateClsObjS(char *inputModelPath, char *inputJsonPath, int in_gpuID, int batchsize = 1);
EXPORT_PKG pClassification *CreateClsObjV3(char *inputModelPath, int in_gpuID, int batchsize);
EXPORT_PKG pClassification *CreateClsObjVT(char* savePath, int in_gpuID);
// EXPORT_PKG pClassification *CreateClsObjV3(char *inputModelPath, int in_gpuID, int batchsize);
EXPORT_PKG pClassification *CreateClsObjF(char *inputModelPath, char *calib, int in_gpuID, int batchsize);
EXPORT_PKG void DestroyClsObj(pClassification *pExport);
class pOCREvaluator
{
public:
virtual ~pOCREvaluator() {}
virtual char *Evaluate(cv::Mat srcImg, std::vector<OCRChar> &resultOcrBox) = 0;
virtual char *Evaluate(const char *imgPath, std::vector<OCRChar> &resultOcrBox) = 0;
virtual void setStride(float stride) = 0;
virtual void setPro(float probability) = 0;
virtual void setSpace(float space) = 0;
virtual OCRStatus getStatus() = 0;
virtual void Release() = 0;
const int m_imageWidth = 0;
const int m_imageHeight = 0;
const int m_classNum = 0;
const int m_inGpuID = 0;
};
EXPORT_PKG pOCREvaluator *CreateOCRObjV3(char *inputModelPath, int batchSize = 1, int in_gpuID = 0);
// EXPORT_PKG pOCREvaluator *CreateOCRObjVT(char *inputModelPath, int in_gpuID);
EXPORT_PKG pOCREvaluator *CreateOCRObjF(char *inputModelPath, char *calib, int in_gpuID);
EXPORT_PKG void DestroyOCRObj(pOCREvaluator *pExport);
EXPORT_PKG bool ConvertOCRtoOCT(char *modelFile, char *clsTxtFile, char *clsModelFile, char *outputPath);
class pDetection
{
public:
virtual ~pDetection() {}
// virtual void Evaluate(cv::Mat srcImg, std::vector<Bbox> &resultBox) = 0;
// virtual void Evaluate(const char* imgPath, std::vector<Bbox> &resultBox) = 0;
virtual std::vector<Bbox> Evaluate(cv::Mat srcImg) = 0;
virtual std::vector<Bbox> Evaluate(const char *imgPath) = 0;
virtual DetStatus getStatus() = 0;
virtual void setStride(float stride) = 0;
virtual void setScore(float score) = 0;
virtual void setNms(float nms) = 0;
virtual void Release() = 0;
const int m_gpuID = 0;
const int batchSizeNet = 0;
const float m_score = 0;
const float m_nms = 0;
const int patchSizeNet = 0;
const float strideNet = 0;
};
EXPORT_PKG pDetection *CreateDetObj(char *modelPath, int batchSize = 1, float stride = 0.9, float score = 0.5, float nms = 0.1, int deviceId = 0);
EXPORT_PKG pDetection *CreateDetObjS(char *modelPath, int batchSize = 1, int deviceId = 0);
EXPORT_PKG void DestroyDetObj(pDetection *pExport);
class pOneClassDetection
{
public:
virtual ~pOneClassDetection() {}
virtual int Train(const char *imgPath, const char *outputPath) = 0;
virtual int Evaluate(cv::Mat srcImg) = 0;
virtual int Evaluate(const char *imgPath) = 0;
virtual cv::Mat Evaluate(cv::Mat srcImg, int &result, float &resultScore) = 0;
virtual cv::Mat Evaluate(const char *imgPath, int &result, float &resultScore) = 0;
// virtual int Evaluate(cv::Mat srcImg, std::vector<float> &rawData) = 0;
virtual cv::Mat Evaluate(cv::Mat srcImg, std::vector<cv::Rect> &resultRects) = 0;
virtual void setThreshold(float threshold) = 0;
virtual float getScore() = 0;
virtual OneStatus getStatus() = 0;
virtual void Release() = 0;
const int m_gpuID = 0;
const int batchSizeNet = 0;
const float m_threScore = 0.8;
const int m_imageWidth = 0;
const int m_imageHeight = 0;
//HD0
const float m_ratio = 1.5;
const float m_ISNG_ratio = 1.0;
const int m_minArea = 400;
const float m_percentile_val = 97;
};
EXPORT_PKG pOneClassDetection *CreateOneObj(char *modelPath, int deviceId = 0);
EXPORT_PKG pOneClassDetection *CreateOneClassObjV2(char* modelPath, int batchSize, int deviceId, int minArea, float ratio, float percentile_val, float ISNG_ratio);
EXPORT_PKG pOneClassDetection *CreateOneClassTrainObj(char *modelPath, int width, int height, int deviceId = 0);
EXPORT_PKG void DestroyOneObj(pOneClassDetection *pExport);
}