1.添加特征值model。
This commit is contained in:
parent
8660c10742
commit
09cb96f97b
@ -9,6 +9,7 @@ add_executable(Analyser Analyser.rc
|
||||
CategoryLogSinkBackend.h CategoryLogSinkBackend.cpp
|
||||
Widget.h Widget.cpp
|
||||
ModuleCommunication.h ModuleCommunication.cpp
|
||||
PalmFeatureTableModel.h PalmFeatureTableModel.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(Analyser
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef MODULECOMMUNICATION_H
|
||||
#define MODULECOMMUNICATION_H
|
||||
|
||||
#include "Database.h"
|
||||
#include "DataStructure.h"
|
||||
#include <QObject>
|
||||
#include <memory>
|
||||
|
||||
|
17
Analyser/PalmFeatureTableModel.cpp
Normal file
17
Analyser/PalmFeatureTableModel.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "PalmFeatureTableModel.h"
|
||||
|
||||
PalmFeatureTableModel::PalmFeatureTableModel(QObject *parent) {
|
||||
}
|
||||
|
||||
int PalmFeatureTableModel::rowCount(const QModelIndex &parent) const {
|
||||
return static_cast<int>(m_features.size());
|
||||
}
|
||||
|
||||
int PalmFeatureTableModel::columnCount(const QModelIndex &parent) const {
|
||||
return 2;
|
||||
}
|
||||
|
||||
QVariant PalmFeatureTableModel::data(const QModelIndex &index, int role) const {
|
||||
QVariant ret;
|
||||
return ret;
|
||||
}
|
19
Analyser/PalmFeatureTableModel.h
Normal file
19
Analyser/PalmFeatureTableModel.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef __PALMFEATURETABLEMODEL_H__
|
||||
#define __PALMFEATURETABLEMODEL_H__
|
||||
|
||||
#include "DataStructure.h"
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
class PalmFeatureTableModel : public QAbstractTableModel {
|
||||
Q_OBJECT
|
||||
public:
|
||||
PalmFeatureTableModel(QObject *parent = nullptr);
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const final;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const final;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const final;
|
||||
|
||||
private:
|
||||
PalmFeatures m_features;
|
||||
};
|
||||
|
||||
#endif // __PALMFEATURETABLEMODEL_H__
|
@ -1,7 +1,9 @@
|
||||
#include "Widget.h"
|
||||
#include "BoostLog.h"
|
||||
#include "CategoryLogSinkBackend.h"
|
||||
#include "Database.h"
|
||||
#include "ModuleCommunication.h"
|
||||
#include "PalmFeatureTableModel.h"
|
||||
#include <QComboBox>
|
||||
#include <QFormLayout>
|
||||
#include <QGridLayout>
|
||||
@ -11,6 +13,7 @@
|
||||
#include <QPushButton>
|
||||
#include <QSerialPortInfo>
|
||||
#include <QTabWidget>
|
||||
#include <QTableView>
|
||||
#include <QTextBrowser>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
@ -51,10 +54,12 @@ Widget::Widget(QWidget *parent) : QWidget{parent} {
|
||||
connect(btn, &QPushButton::clicked, this, &Widget::onClearLogButtonClicked);
|
||||
logLayout->addWidget(btn, 0, Qt::AlignBottom | Qt::AlignRight);
|
||||
|
||||
m_featureTableView = new QTableView();
|
||||
|
||||
auto tabWidget = new QTabWidget();
|
||||
tabWidget->addTab(m_logBrowser, "日志");
|
||||
tabWidget->addTab(new QWidget(), "视频流");
|
||||
tabWidget->addTab(new QWidget(), "已注册列表");
|
||||
tabWidget->addTab(m_featureTableView, "本地特征值列表");
|
||||
|
||||
m_commandGroupBox = initializeCommandGroupBox();
|
||||
|
||||
@ -68,6 +73,8 @@ Widget::Widget(QWidget *parent) : QWidget{parent} {
|
||||
layout->addWidget(tabWidget, 3);
|
||||
|
||||
m_database = std::make_shared<Database>();
|
||||
m_featureModel = new PalmFeatureTableModel(this);
|
||||
m_featureTableView->setModel(m_featureModel);
|
||||
|
||||
QTimer::singleShot(0, this, [this]() {
|
||||
onSerialRefreshButtonClicked();
|
||||
@ -194,14 +201,14 @@ QGroupBox *Widget::initializeUvcGroupBox() {
|
||||
}
|
||||
|
||||
void Widget::onNewPalmFeature(const PalmFeature &feature) {
|
||||
auto palms = m_database->palmFeatures();
|
||||
if (std::find(palms.cbegin(), palms.cend(), feature) != palms.cend()) {
|
||||
LOG(warning) << "本地数据库已有相同特征数据。";
|
||||
return;
|
||||
}
|
||||
if (!m_database->addPalmFeature(feature)) {
|
||||
LOG(error) << "add palm feature failed.";
|
||||
}
|
||||
|
||||
auto palms = m_database->palmFeatures();
|
||||
for (auto &p : palms) {
|
||||
LOG(info) << p.id << " " << p.username << " " << p.feature.size();
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::onSerialConnectButtonClicked() {
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef WIDGET_H
|
||||
#define WIDGET_H
|
||||
|
||||
#include "Database.h"
|
||||
#include "DataStructure.h"
|
||||
#include <QWidget>
|
||||
|
||||
class QPushButton;
|
||||
@ -9,7 +9,10 @@ class QTextBrowser;
|
||||
class QComboBox;
|
||||
class QLineEdit;
|
||||
class QGroupBox;
|
||||
class QTableView;
|
||||
class ModuleCommunication;
|
||||
class PalmFeatureTableModel;
|
||||
class Database;
|
||||
|
||||
class Widget : public QWidget {
|
||||
Q_OBJECT
|
||||
@ -63,6 +66,9 @@ private:
|
||||
|
||||
std::shared_ptr<ModuleCommunication> m_communication;
|
||||
std::shared_ptr<Database> m_database;
|
||||
|
||||
PalmFeatureTableModel *m_featureModel = nullptr;
|
||||
QTableView *m_featureTableView = nullptr;
|
||||
};
|
||||
|
||||
#endif // WIDGET_H
|
||||
|
@ -1,5 +1,6 @@
|
||||
add_library(Database
|
||||
Database.h Database.cpp
|
||||
DataStructure.h DataStructure.cpp
|
||||
# shell.c
|
||||
sqlite3.h sqlite3.c
|
||||
sqlite3ext.h
|
||||
|
5
Database/DataStructure.cpp
Normal file
5
Database/DataStructure.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include "DataStructure.h"
|
||||
|
||||
bool operator==(const PalmFeature &lhs, const PalmFeature &rhs) {
|
||||
return lhs.feature == rhs.feature;
|
||||
}
|
23
Database/DataStructure.h
Normal file
23
Database/DataStructure.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef __DATASTRUCTURE_H__
|
||||
#define __DATASTRUCTURE_H__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class PalmFeature {
|
||||
public:
|
||||
int64_t id; // 对应本地数据库的id
|
||||
std::string username;
|
||||
std::vector<uint8_t> feature;
|
||||
};
|
||||
|
||||
using PalmFeatures = std::vector<PalmFeature>;
|
||||
|
||||
bool operator==(const PalmFeature &lhs, const PalmFeature &rhs);
|
||||
|
||||
namespace std {
|
||||
template <>
|
||||
struct hash<PalmFeature> {};
|
||||
} // namespace std
|
||||
|
||||
#endif // __DATASTRUCTURE_H__
|
@ -23,8 +23,8 @@ bool Database::addPalmFeature(const PalmFeature &palm) {
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<PalmFeature> Database::palmFeatures() const {
|
||||
std::vector<PalmFeature> ret;
|
||||
PalmFeatures Database::palmFeatures() const {
|
||||
PalmFeatures ret;
|
||||
sqlite3_stmt *statement = nullptr;
|
||||
constexpr const char *sql = "SELECT * FROM palm_feature";
|
||||
if (sqlite3_prepare_v2(m_sqlite, sql, -1, &statement, NULL) != SQLITE_OK) {
|
||||
|
@ -1,23 +1,16 @@
|
||||
#ifndef __DATABASE_H__
|
||||
#define __DATABASE_H__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "DataStructure.h"
|
||||
|
||||
struct sqlite3;
|
||||
|
||||
class PalmFeature {
|
||||
public:
|
||||
int64_t id; // 对应本地数据库的id
|
||||
std::string username;
|
||||
std::vector<uint8_t> feature;
|
||||
};
|
||||
|
||||
class Database{
|
||||
public:
|
||||
bool open(const std::string &path);
|
||||
bool addPalmFeature(const PalmFeature &palm);
|
||||
std::vector<PalmFeature> palmFeatures() const;
|
||||
PalmFeatures palmFeatures() const;
|
||||
|
||||
private:
|
||||
void initializeTables();
|
||||
|
Loading…
Reference in New Issue
Block a user