inferthread.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #ifndef INFERTHREAD_H
  2. #define INFERTHREAD_H
  3. #include <QObject>
  4. #include <QString>
  5. #include <QException>
  6. #include <QDebug>
  7. #include <QPixmap>
  8. #include <QtWidgets/QPushButton>
  9. #include <QtWidgets/QLabel>
  10. #include <QThread>
  11. #include "opencv2/opencv.hpp"
  12. #include "opencv2/core/core.hpp"
  13. #include "opencv2/highgui/highgui.hpp"
  14. #include "opencv2/imgproc/imgproc.hpp"
  15. using namespace cv;
  16. // Model inference API: det, seg, clas, mask
  17. typedef void (*Det_ModelPredict)(const unsigned char* ,
  18. int , int , int ,
  19. float* , int* , char* );
  20. typedef void (*Seg_ModelPredict)(const unsigned char* ,
  21. int , int , int ,
  22. unsigned char* );
  23. typedef void (*Cls_ModelPredict)(const unsigned char* ,
  24. int , int , int ,
  25. float* , char* , int* );
  26. typedef void (*Mask_ModelPredict)(const unsigned char* ,
  27. int , int , int ,
  28. float* , unsigned char* ,
  29. int* , char* );
  30. class InferThread : public QThread
  31. {
  32. Q_OBJECT
  33. private:
  34. QString model_Type;
  35. uchar *color_map; // visual color table/map
  36. QString image_path;
  37. QStringList images_path;
  38. QString video_path;
  39. public:
  40. float det_Threshold; // Target detection threshold
  41. int infer_Delay; // Continuous inference interval
  42. bool doing_Infer; // Sign reasoning
  43. bool break_Infer; // Terminate continuous reasoning/video reasoning
  44. bool dataLoaded; // Whether data has been loaded
  45. QImage* label1_image;
  46. QImage* label2_image;
  47. Mat* image1;
  48. Mat* image2;
  49. private:
  50. // Model inference API
  51. Det_ModelPredict det_ModelPredict;
  52. Seg_ModelPredict seg_ModelPredict;
  53. Cls_ModelPredict cls_ModelPredict;
  54. Mask_ModelPredict mask_ModelPredict;
  55. private:
  56. // don`t use
  57. QPushButton *btnStop; // Point to the external termination button
  58. QPushButton *btnInfer; // Point to the external reasoning button
  59. QLabel *labelImage1; // Image display area-Label--left
  60. QLabel *labelImage2; // Image display area-Label--right
  61. public:
  62. void setStopBtn(QPushButton *btn);
  63. void setInferBtn(QPushButton *btn);
  64. void setDetThreshold(float threshold);
  65. void setInferDelay(int delay);
  66. uchar* get_color_map_list(int num_classes=256);
  67. public:
  68. explicit InferThread(QObject *parent = nullptr);
  69. void setModelType(QString & model_type); // Setting the model type of reasoning - use the correct model reasoning interface
  70. void setInputImage(QString & image_path);
  71. void setInputImages(QStringList & images_path);
  72. void setInputVideo(QString & video_path);
  73. void setInferFuncs(Det_ModelPredict det_Inferfunc, Seg_ModelPredict seg_Inferfunc,
  74. Cls_ModelPredict cls_Inferfunc, Mask_ModelPredict mask_Inferfunc);
  75. void runInferDet();
  76. void runInferSeg();
  77. void runInferCls();
  78. void runInferMask();
  79. void run() override; // Execute this thread
  80. private:
  81. bool is_InferImage();
  82. bool is_InferImages();
  83. bool is_InferVideo();
  84. QString makeLabelInfo(QString label, int id, float score);
  85. // Detecting the inference interface
  86. public:
  87. void Det_Image();
  88. void Det_Images();
  89. void Det_Video();
  90. // Semantic segmentation reasoning interface
  91. public:
  92. void Seg_Image();
  93. void Seg_Images();
  94. void Seg_Video();
  95. // Classification inference interface
  96. public:
  97. void Cls_Image();
  98. void Cls_Images();
  99. void Cls_Video();
  100. // Instance split reasoning interface
  101. public:
  102. void Mask_Image();
  103. void Mask_Images();
  104. void Mask_Video();
  105. signals:
  106. void InferFinished(QImage* label1, QImage* label2);
  107. void SetState_Btn_StopAndInfer(bool stop_state, bool infer_state);
  108. void SetCostTime(double cost_time);
  109. public slots:
  110. };
  111. #endif // INFERTHREAD_H