handwritingengine.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef HANDWRITINGENGINE_H
  2. #define HANDWRITINGENGINE_H
  3. #include <QObject>
  4. #include <QUrl>
  5. #include <QByteArray>
  6. #include <QtProtobufTypes>
  7. #include "matrix.h"
  8. #include <memory>
  9. namespace handwriting {
  10. class HandwritingClient;
  11. }
  12. class HandwritingEngine final : public QObject
  13. {
  14. Q_OBJECT
  15. Q_PROPERTY(int result READ result WRITE setResult NOTIFY resultChanged)
  16. Q_PROPERTY(handwriting::Matrix *matrix READ matrix CONSTANT)
  17. public:
  18. explicit HandwritingEngine(QObject *parent = nullptr);
  19. virtual ~HandwritingEngine() = default;
  20. Q_INVOKABLE void retrain();
  21. Q_INVOKABLE void recognize();
  22. Q_INVOKABLE void setNeuralNetworkData(const QString &networkDataPath);
  23. Q_INVOKABLE void updateValue(int index, double value);
  24. int result() const
  25. {
  26. return m_result;
  27. }
  28. handwriting::Matrix *matrix()
  29. {
  30. return &m_matrix;
  31. }
  32. public slots:
  33. void setResult(int result)
  34. {
  35. if (m_result == result)
  36. return;
  37. m_result = result;
  38. emit resultChanged(m_result);
  39. }
  40. signals:
  41. void resultChanged(int result);
  42. private:
  43. std::shared_ptr<handwriting::HandwritingClient> m_client;
  44. int m_result;
  45. QtProtobuf::DoubleList m_data;
  46. handwriting::Matrix m_matrix;
  47. };
  48. #endif // HANDWRITINGENGINE_H