202 lines
3.9 KiB
C
202 lines
3.9 KiB
C
![]() |
#pragma once
|
|||
|
|
|||
|
#include "vector"
|
|||
|
#include <memory>
|
|||
|
#include "string"
|
|||
|
#include "opencv2/opencv.hpp"
|
|||
|
|
|||
|
#ifndef mymax
|
|||
|
#define mymin(x,y) ((x) < (y) ? (x) : (y))
|
|||
|
#define mymax(x,y) ((x) > (y) ? (x) : (y))
|
|||
|
#endif // mymax
|
|||
|
|
|||
|
|
|||
|
#ifndef _DetectorResult
|
|||
|
#define _DetectorResult
|
|||
|
struct DetectorResult
|
|||
|
{
|
|||
|
int image_id, label; //label 1 <20><>ʼ 0 <20><><EFBFBD><EFBFBD>
|
|||
|
char name[16];
|
|||
|
float score;
|
|||
|
int left, top, height, width;
|
|||
|
bool overlap;
|
|||
|
bool hasMask;
|
|||
|
int area;
|
|||
|
cv::Mat mask;
|
|||
|
DetectorResult()
|
|||
|
{
|
|||
|
memset(name, 0, sizeof(name));
|
|||
|
}
|
|||
|
DetectorResult(int label, float left, float top, float width, float height, float score)
|
|||
|
{
|
|||
|
this->image_id = 0;
|
|||
|
this->label = label;
|
|||
|
this->left = left;
|
|||
|
this->width = width;
|
|||
|
this->top = top;
|
|||
|
this->height = height;
|
|||
|
this->score = score;
|
|||
|
this->area = width * height;
|
|||
|
}
|
|||
|
DetectorResult(const DetectorResult& detectorResult)
|
|||
|
{
|
|||
|
this->image_id = detectorResult.image_id;
|
|||
|
this->label = detectorResult.label;
|
|||
|
strcpy_s(this->name, detectorResult.name);
|
|||
|
this->left = detectorResult.left;
|
|||
|
this->width = detectorResult.width;
|
|||
|
this->top = detectorResult.top;
|
|||
|
this->height = detectorResult.height;
|
|||
|
this->score = detectorResult.score;
|
|||
|
this->area = detectorResult.area;
|
|||
|
this->overlap = detectorResult.overlap;
|
|||
|
this->hasMask = detectorResult.hasMask;
|
|||
|
if (!detectorResult.mask.empty())
|
|||
|
this->mask = detectorResult.mask.clone();
|
|||
|
}
|
|||
|
|
|||
|
void Offset(int offsetX, int offsetY)
|
|||
|
{
|
|||
|
left += offsetX;
|
|||
|
top += offsetY;
|
|||
|
}
|
|||
|
|
|||
|
void Scale(float scaleX, float scaleY)
|
|||
|
{
|
|||
|
left *= scaleX;
|
|||
|
top *= scaleY;
|
|||
|
width *= scaleX;
|
|||
|
height *= scaleY;
|
|||
|
}
|
|||
|
|
|||
|
void ScaleOffset(float scaleX, float scaleY, int offsetX, int offsetY)
|
|||
|
{
|
|||
|
Scale(scaleX, scaleY);
|
|||
|
Offset(offsetX, offsetY);
|
|||
|
}
|
|||
|
|
|||
|
void OffsetScale(int offsetX, int offsetY, float scaleX, float scaleY)
|
|||
|
{
|
|||
|
Offset(offsetX, offsetY);
|
|||
|
Scale(scaleX, scaleY);
|
|||
|
}
|
|||
|
|
|||
|
void Clip(int iMinX, int iMaxX, int iMinY, int iMaxY)
|
|||
|
{
|
|||
|
int right = left + width;
|
|||
|
int bottom = top + height;
|
|||
|
|
|||
|
left = mymax(iMinX, left);
|
|||
|
top = mymax(iMinY, top);
|
|||
|
|
|||
|
right = mymin(right, iMaxX);
|
|||
|
bottom = mymin(bottom, iMaxY);
|
|||
|
|
|||
|
width = right - left;
|
|||
|
height = bottom - top;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
cv::Rect GetRect()
|
|||
|
{
|
|||
|
cv::Rect cvRect(left, top, width, height);
|
|||
|
return cvRect;
|
|||
|
}
|
|||
|
|
|||
|
};
|
|||
|
#endif
|
|||
|
|
|||
|
|
|||
|
#ifndef _FaultDetectResult
|
|||
|
#define _FaultDetectResult
|
|||
|
struct FaultDetectResult
|
|||
|
{
|
|||
|
int image_id, label; //label 1 <20><>ʼ 0 <20><><EFBFBD><EFBFBD>
|
|||
|
char name[16];
|
|||
|
float score;
|
|||
|
float value;
|
|||
|
int left, top, height, width;
|
|||
|
bool overlap;
|
|||
|
bool hasMask;
|
|||
|
cv::Mat mask;
|
|||
|
FaultDetectResult()
|
|||
|
{
|
|||
|
}
|
|||
|
FaultDetectResult(int label, float left, float top, float width, float height, float score)
|
|||
|
{
|
|||
|
this->image_id = 0;
|
|||
|
this->label = label;
|
|||
|
this->left = left;
|
|||
|
this->width = width;
|
|||
|
this->top = top;
|
|||
|
this->height = height;
|
|||
|
this->score = score;
|
|||
|
}
|
|||
|
|
|||
|
void Offset(int offsetX, int offsetY)
|
|||
|
{
|
|||
|
left += offsetX;
|
|||
|
top += offsetY;
|
|||
|
}
|
|||
|
|
|||
|
void Scale(float scaleX, float scaleY)
|
|||
|
{
|
|||
|
left *= scaleX;
|
|||
|
top *= scaleY;
|
|||
|
width *= scaleX;
|
|||
|
height *= scaleY;
|
|||
|
}
|
|||
|
|
|||
|
void ScaleOffset(float scaleX, float scaleY, int offsetX, int offsetY)
|
|||
|
{
|
|||
|
Scale(scaleX, scaleY);
|
|||
|
Offset(offsetX, offsetY);
|
|||
|
}
|
|||
|
|
|||
|
void OffsetScale(int offsetX, int offsetY, float scaleX, float scaleY)
|
|||
|
{
|
|||
|
Offset(offsetX, offsetY);
|
|||
|
Scale(scaleX, scaleY);
|
|||
|
}
|
|||
|
|
|||
|
cv::Rect GetRect()
|
|||
|
{
|
|||
|
cv::Rect cvRect(left, top, width, height);
|
|||
|
return cvRect;
|
|||
|
}
|
|||
|
|
|||
|
};
|
|||
|
#endif
|
|||
|
|
|||
|
|
|||
|
#ifndef _SInferenceParams
|
|||
|
#define _SInferenceParams
|
|||
|
struct SInferenceParams
|
|||
|
{
|
|||
|
std::string init_net_pb, predict_net_pb;
|
|||
|
int batchSize = 1;
|
|||
|
int minSize = 800;
|
|||
|
int maxSize = 1333;
|
|||
|
float threshold = 0.5;
|
|||
|
bool hasMask = true;
|
|||
|
};
|
|||
|
#endif
|
|||
|
|
|||
|
struct IObjectDetector
|
|||
|
{
|
|||
|
public:
|
|||
|
virtual ~IObjectDetector() = default;
|
|||
|
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
virtual bool Init() = 0;
|
|||
|
//<2F>ͷŶ<CDB7><C5B6><EFBFBD>
|
|||
|
virtual bool UnInit() = 0;
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
virtual const char* GetType() = 0;
|
|||
|
//ִ<><D6B4>infer
|
|||
|
virtual bool Execute(cv::Mat& image) = 0;
|
|||
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|||
|
virtual bool GetResults(std::vector<DetectorResult>& vecDetectorResults) = 0;
|
|||
|
};
|
|||
|
|
|||
|
|
|||
|
float Iou(cv::Rect box1, cv::Rect box2);
|