You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

widget.h 3.4 kB

5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * Copyright (C) 2021 刘臣轩
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef WIDGET_H
  18. #define WIDGET_H
  19. #include <QDebug>
  20. #include <QMessageBox>
  21. #include <QThread>
  22. #include <QWidget>
  23. #include <QFileDialog>
  24. #include <QMediaPlayer>
  25. #include <QMediaPlaylist>
  26. #include <QVideoWidget>
  27. #include <QBuffer>
  28. #include <QByteArray>
  29. #include <QFile>
  30. #include <QDateTime>
  31. #include <QTextCodec>
  32. #include <QTimer>
  33. #include <QSerialPort>
  34. #include <QSerialPortInfo>
  35. #include <QCamera>
  36. #include <QCameraImageCapture>
  37. #include <QCameraInfo>
  38. #include <QCameraViewfinder>
  39. #include <QNetworkAccessManager>
  40. #include <QNetworkReply>
  41. #include <QNetworkRequest>
  42. #include <QUrlQuery>
  43. #include <QCryptographicHash>
  44. #include <QJsonArray>
  45. #include <QJsonDocument>
  46. #include <QJsonObject>
  47. #include "tensorflow.h"
  48. #include "stdint.h"
  49. #include "opencv2/opencv.hpp"
  50. #include <sys/stat.h>
  51. #if _MSC_VER >= 1600
  52. #pragma execution_character_set("utf-8")
  53. #endif
  54. QT_BEGIN_NAMESPACE
  55. namespace Ui {
  56. class Widget;
  57. }
  58. QT_END_NAMESPACE
  59. class Widget : public QWidget {
  60. Q_OBJECT
  61. public:
  62. Widget(QWidget* parent = nullptr);
  63. ~Widget();
  64. private:
  65. Ui::Widget* ui;
  66. QTimer* videoTimer;
  67. QMediaPlayer* player;
  68. QVideoWidget* videoWidget;
  69. QMediaPlaylist* playList;
  70. QSerialPort* serialPort;
  71. void initSerial();
  72. void serialWrite(const char data);
  73. QCamera* camera;
  74. QCameraViewfinder* viewFinder;
  75. QCameraImageCapture* imageCapture;
  76. void initCamera();
  77. void captureImage();
  78. QNetworkAccessManager* networkManager;
  79. QNetworkRequest* networkRequest;
  80. QUrl* url;
  81. void sendRequest(QByteArray& imageBase64);
  82. void classifyFinished(QString cate_name);
  83. qint64 number;
  84. #ifdef Q_OS_WIN
  85. #else
  86. std::string model_file = "../WasteSorting/tensorflow/model.tflite";
  87. std::unique_ptr<tflite::FlatBufferModel> model;
  88. std::unique_ptr<tflite::Interpreter> interpreter;
  89. tflite::ops::builtin::BuiltinOpResolver resolver;
  90. TfLiteTensor* input_tensor;
  91. template <class T>
  92. void formatImageTFLite(T* out, const uint8_t* in, int image_height, int image_width, int image_channels, int wanted_height, int wanted_width, int wanted_channels, bool input_floating);
  93. template <class T>
  94. void get_top_n(T* prediction, int prediction_size, size_t num_results,
  95. float threshold, std::vector<std::pair<float, int>>* top_results,
  96. TfLiteType input_type);
  97. int output_size;
  98. #endif
  99. cv::VideoCapture capture;
  100. QImage cvMat2QImage(const cv::Mat& mat);
  101. private slots:
  102. void timerUpdate();
  103. void videoTimerUpdate();
  104. void serialRead();
  105. void onImageCaptured(int, QImage image);
  106. void onRequestFinished(QNetworkReply* reply);
  107. signals:
  108. void imageCaptured(int, QImage);
  109. };
  110. #endif // WIDGET_H

No Description