12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #include<iostream>
- #include <opencv2/opencv.hpp>
- #include <opencv2/highgui/highgui_c.h>
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <cstdlib>
- #include <fstream>
- //#include "MeterRead.h"
- using namespace std;
- //using namespace cv::dnn;
- #define YOLO_P6 false //是否使用P6模型
- struct Output {
- int id; //结果类别id
- float confidence; //结果置信度
- cv::Rect box; //矩形框
- };
- class ClassifyDectect {
- public:
- ClassifyDectect() {
- }
- ~ClassifyDectect() {}
- bool Init(bool isCuda);
- bool Detect(cv::Mat& SrcImg, std::vector<Output>& output);
- void drawPred(cv::Mat& img, std::vector<Output> result);
- void modifyConfidenceParameter(float boxThreshold, float classThreshold, float nmsThreshold);
- private:
- cv::dnn::Net net;
- #if(defined YOLO_P6 && YOLO_P6==true)
- const float netAnchors[4][6] = { { 19,27, 44,40, 38,94 },{ 96,68, 86,152, 180,137 },{ 140,301, 303,264, 238,542 },{ 436,615, 739,380, 925,792 } };
- const int netWidth = 1280; //ONNX图片输入宽度
- const int netHeight = 1280; //ONNX图片输入高度
- const int strideSize = 4; //stride size
- #else
- const float netAnchors[3][6] = { { 10,13, 16,30, 33,23 },{ 30,61, 62,45, 59,119 },{ 116,90, 156,198, 373,326 } };
- const int netWidth = 640; //ONNX图片输入宽度
- const int netHeight = 640; //ONNX图片输入高度
- const int strideSize = 3; //stride size
- #endif // YOLO_P6
- const float netStride[4] = { 8, 16.0,32,64 };
- float boxThreshold = 0.35;
- float classThreshold = 0.35;
- float nmsThreshold = 0.55;
- float nmsScoreThreshold = boxThreshold * classThreshold;
- public:
- const std::vector<std::string> className = {
- "disconnector",
- "oil_level",
- "meter",
- "changeover_switch",
- "pressplate",
- "disconnector_state",
- "light",
- "air_switch",
- "character",
- "indoor_disconnector",
- "triangle_disconnector",
- "electron_plate",
- "contact",
- "instructions",
- "operating_handle",
- "person",
- "fire",
- "smoke",
- "circle_off_on_plate"
- };
- const std::string instructionsName = "instructions";
- };
|