handwritingengine.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 recognize();
  21. Q_INVOKABLE void setNeuralNetworkData(const QString &networkDataPath);
  22. int result() const
  23. {
  24. return m_result;
  25. }
  26. handwriting::Matrix *matrix()
  27. {
  28. return &m_matrix;
  29. }
  30. public slots:
  31. void setResult(int result)
  32. {
  33. if (m_result == result)
  34. return;
  35. m_result = result;
  36. emit resultChanged(m_result);
  37. }
  38. signals:
  39. void resultChanged(int result);
  40. private:
  41. std::shared_ptr<handwriting::HandwritingClient> m_client;
  42. int m_result;
  43. QtProtobuf::DoubleList m_data;
  44. handwriting::Matrix m_matrix;
  45. };
  46. #endif // HANDWRITINGENGINE_H