AppearanceClassifyDectect.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include<iostream>
  2. #include <opencv2/opencv.hpp>
  3. #include <opencv2/highgui/highgui_c.h>
  4. #include <iostream>
  5. #include <vector>
  6. #include <algorithm>
  7. #include <cstdlib>
  8. #include <fstream>
  9. using namespace std;
  10. //using namespace cv::dnn;
  11. #define YOLO_P6 false //是否使用P6模型
  12. struct Output2 {
  13. int id; //结果类别id
  14. float confidence; //结果置信度
  15. cv::Rect box; //矩形框
  16. };
  17. class AppearanceClassifyDectect{
  18. public:
  19. AppearanceClassifyDectect() {
  20. }
  21. ~AppearanceClassifyDectect() {}
  22. bool Init(bool isCuda);
  23. bool Detect(cv::Mat& SrcImg, std::vector<Output2>& output2);
  24. void drawPred(cv::Mat& img, std::vector<Output2> result2);
  25. void modifyConfidenceParameter(float boxThreshold, float classThreshold, float nmsThreshold);
  26. private:
  27. cv::dnn::Net net;
  28. #if(defined YOLO_P6 && YOLO_P6==true)
  29. 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 } };
  30. const int netWidth = 1280; //ONNX图片输入宽度
  31. const int netHeight = 1280; //ONNX图片输入高度
  32. const int strideSize = 4; //stride size
  33. #else
  34. const float netAnchors[3][6] = { { 10,13, 16,30, 33,23 },{ 30,61, 62,45, 59,119 },{ 116,90, 156,198, 373,326 } };
  35. const int netWidth = 640; //ONNX图片输入宽度
  36. const int netHeight = 640; //ONNX图片输入高度
  37. const int strideSize = 3; //stride size
  38. #endif // YOLO_P6
  39. const float netStride[4] = { 8, 16.0,32,64 };
  40. float boxThreshold = 0.35;
  41. float classThreshold = 0.35;
  42. float nmsThreshold = 0.55;
  43. float nmsScoreThreshold = boxThreshold * classThreshold;
  44. public:
  45. const std::vector<std::string> className = {
  46. "oil",
  47. "insulator",
  48. "person"
  49. };
  50. const std::string instructionsName = "instructions";
  51. };