实现图片下发识别。
This commit is contained in:
parent
bdc7711bbb
commit
1277ef7495
@ -216,7 +216,7 @@ void Application::enrollExtended(const QString &username, bool persistence, uint
|
||||
m_palmUsername = username;
|
||||
}
|
||||
|
||||
void Application::uploadImage(const QString &path, int operation) {
|
||||
void Application::uploadImage(const QString &path, const QString &username, int operation) {
|
||||
m_uploadImageSendedSize = 0;
|
||||
ModuleCommunication::UploadImageInformation request;
|
||||
if (path.endsWith(".jpg")) {
|
||||
@ -226,7 +226,7 @@ void Application::uploadImage(const QString &path, int operation) {
|
||||
return;
|
||||
}
|
||||
m_uploadBuffer = image->data;
|
||||
LOG(info) << "width: " << image->width << ", height: " << image->height;
|
||||
LOG(info) << path.toStdString() << ", width: " << image->width << ", height: " << image->height;
|
||||
request.width = image->width;
|
||||
request.height = image->height;
|
||||
} else if (path.endsWith(".yuv")) {
|
||||
@ -251,22 +251,17 @@ void Application::uploadImage(const QString &path, int operation) {
|
||||
|
||||
request.operation = operation;
|
||||
request.size = m_uploadBuffer.size();
|
||||
strncpy(request.username, "下发测试", sizeof(request.username));
|
||||
strncpy(request.username, username.toStdString().c_str(), sizeof(request.username));
|
||||
m_communication->uploadImageInfo(request);
|
||||
LOG(info) << "upload image, md5: "
|
||||
<< ModuleCommunication::protocolDataFormatString(request.md5, sizeof(request.md5));
|
||||
m_imageUploadling = true;
|
||||
m_uploadPath = path;
|
||||
m_uploadUsername = username;
|
||||
m_currentUploadOperation = operation;
|
||||
m_startUploadTime = std::chrono::system_clock::now();
|
||||
}
|
||||
|
||||
void Application::timerEvent(QTimerEvent *event) {
|
||||
static int i = 0;
|
||||
if (i <= 4000 && !m_imageUploadling) {
|
||||
uploadImage("./1722829247678.jpg", 0);
|
||||
LOG(info) << "register times: " << i++;
|
||||
}
|
||||
}
|
||||
|
||||
ModuleCommunication *Application::module() const {
|
||||
return m_communication.get();
|
||||
}
|
||||
@ -290,6 +285,17 @@ void Application::setPersistenceMode(bool enabled) {
|
||||
}
|
||||
}
|
||||
|
||||
bool Application::imageUploadPersistenceMode() const {
|
||||
return m_imageUploadPersistenceMode;
|
||||
}
|
||||
|
||||
void Application::setImageUploadPersistenceMode(bool enabled) {
|
||||
if (m_imageUploadPersistenceMode != enabled) {
|
||||
m_imageUploadPersistenceMode = enabled;
|
||||
emit imageUploadPersistenceModeChanged();
|
||||
}
|
||||
}
|
||||
|
||||
int Application::persistenceVerifyInterval() const {
|
||||
return m_persistenceVerifyInterval;
|
||||
}
|
||||
@ -386,10 +392,15 @@ void Application::onCommandFinished(ModuleCommunication::MessageId messageId,
|
||||
(const uint8_t *)m_uploadBuffer.data() + m_uploadImageSendedSize,
|
||||
remainSize < ImageSliceSize ? remainSize : ImageSliceSize);
|
||||
m_imageUploadling = true;
|
||||
} else {
|
||||
LOG(info) << "upload finished, elapsed: "
|
||||
<< duration_cast<milliseconds>(system_clock::now() - m_startUploadTime);
|
||||
}
|
||||
if (status != ModuleCommunication::Needmore) {
|
||||
LOG(info) << "upload image finished, status: " << static_cast<int>(status)
|
||||
<< ", elapsed: " << duration_cast<milliseconds>(system_clock::now() - m_startUploadTime);
|
||||
m_imageUploadling = false;
|
||||
if (m_imageUploadPersistenceMode) {
|
||||
QTimer::singleShot(1, this,
|
||||
[this]() { uploadImage(m_uploadPath, m_uploadUsername, m_currentUploadOperation); });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -404,7 +415,8 @@ void Application::onCommandFinished(ModuleCommunication::MessageId messageId,
|
||||
if (m_persistenceMode && m_persistenceModeStarted &&
|
||||
((messageId == ModuleCommunication::Verify) || (messageId == ModuleCommunication::VerifyExtended)) &&
|
||||
((status == ModuleCommunication::Success) || (status == ModuleCommunication::Failed4UnknownUser) ||
|
||||
(status == ModuleCommunication::Failed4Timeout) || (status == ModuleCommunication::Failed4UnknownReason))) {
|
||||
(status == ModuleCommunication::Failed4Timeout) || (status == ModuleCommunication::Failed4UnknownReason) ||
|
||||
(status == ModuleCommunication::Failed4LivenessCheck))) {
|
||||
m_verifyTimer->start(m_persistenceVerifyInterval * 1000);
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,8 @@ class Application : public QObject {
|
||||
Q_PROPERTY(bool connected READ connected NOTIFY connectedChanged)
|
||||
Q_PROPERTY(bool uvcOpened READ uvcOpened NOTIFY uvcOpenedChanged)
|
||||
Q_PROPERTY(bool persistenceMode READ persistenceMode WRITE setPersistenceMode NOTIFY persistenceModeChanged)
|
||||
Q_PROPERTY(bool imageUploadPersistenceMode READ imageUploadPersistenceMode WRITE setImageUploadPersistenceMode
|
||||
NOTIFY imageUploadPersistenceModeChanged)
|
||||
Q_PROPERTY(int persistenceVerifyInterval READ persistenceVerifyInterval WRITE setPersistenceVerifyInterval NOTIFY
|
||||
persistenceVerifyIntervalChanged)
|
||||
Q_PROPERTY(bool isVerifying READ isVerifying NOTIFY isVerifyingChanged)
|
||||
@ -51,12 +53,14 @@ public:
|
||||
Q_INVOKABLE void enrollExtended(const QString &username, bool persistence, uint8_t timeout);
|
||||
Q_INVOKABLE void deleteUser(uint16_t userid);
|
||||
Q_INVOKABLE void deleteAll();
|
||||
Q_INVOKABLE void uploadImage(const QString &path, int operation);
|
||||
Q_INVOKABLE void uploadImage(const QString &path, const QString &username, int operation);
|
||||
ModuleCommunication *module() const;
|
||||
bool connected() const;
|
||||
bool uvcOpened() const;
|
||||
bool persistenceMode() const;
|
||||
void setPersistenceMode(bool enabled);
|
||||
bool imageUploadPersistenceMode() const;
|
||||
void setImageUploadPersistenceMode(bool enabled);
|
||||
|
||||
int persistenceVerifyInterval() const;
|
||||
void setPersistenceVerifyInterval(int interval);
|
||||
@ -66,6 +70,7 @@ signals:
|
||||
void connectedChanged();
|
||||
void persistenceModeChanged();
|
||||
void persistenceVerifyIntervalChanged();
|
||||
void imageUploadPersistenceModeChanged();
|
||||
void isVerifyingChanged();
|
||||
void uvcOpenedChanged();
|
||||
void newVideoFrame();
|
||||
@ -77,7 +82,6 @@ signals:
|
||||
|
||||
protected:
|
||||
Application(int &argc, char **argv);
|
||||
void timerEvent(QTimerEvent *event) final;
|
||||
void onNewEnrollResult(uint16_t userid);
|
||||
void onNewVerifyResult(uint16_t userid, const QString &username, uint16_t elapsed);
|
||||
void onNewPalmFeature(const PalmFeature &feature);
|
||||
@ -111,7 +115,11 @@ private:
|
||||
|
||||
uint32_t m_uploadImageSendedSize;
|
||||
std::vector<uint8_t> m_uploadBuffer;
|
||||
int m_currentUploadOperation = 0;
|
||||
QString m_uploadPath;
|
||||
QString m_uploadUsername;
|
||||
bool m_imageUploadling = false;
|
||||
bool m_imageUploadPersistenceMode = false;
|
||||
|
||||
std::shared_ptr<VideoPlayer> m_videoPlayer;
|
||||
VideoFrameProvider *m_videoFrameProvider;
|
||||
|
@ -249,7 +249,7 @@ void ModuleCommunication::processPackage(const uint8_t *data, uint16_t size) {
|
||||
LOG_CAT(info, GUI) << "注册成功,用户ID: " << userId << ", 图片大小: " << width << "x" << height;
|
||||
emit newImageInfo(static_cast<MessageId>(replyId), width * height, info->md5);
|
||||
} else {
|
||||
auto info = reinterpret_cast<const EnrollDataReply *>(data + 7);
|
||||
auto info = reinterpret_cast<const EnrollReply *>(data + 7);
|
||||
userId = ntohs(info->userid);
|
||||
LOG_CAT(info, GUI) << "注册成功,用户ID: " << userId;
|
||||
}
|
||||
@ -296,13 +296,23 @@ void ModuleCommunication::processPackage(const uint8_t *data, uint16_t size) {
|
||||
break;
|
||||
}
|
||||
case UploadImageData: {
|
||||
auto info = reinterpret_cast<const UploadImageReply *>(data + 7);
|
||||
if (result == Success) {
|
||||
auto info = reinterpret_cast<const EnrollDataReply *>(data + 7);
|
||||
if (info->operation == 0) {
|
||||
LOG_CAT(info, GUI) << "图片下发注册成功,用户ID: " << ntohs(info->userid);
|
||||
} else if (info->operation == 1) {
|
||||
auto result = reinterpret_cast<const UploadImageVerifyReply *>(info);
|
||||
LOG_CAT(info, GUI) << "图片下发识别成功,用户ID: " << ntohs(result->userid) << ", 用户名: "
|
||||
<< std::string_view(reinterpret_cast<const char *>(result->result.username))
|
||||
<< ", 耗时: " << ntohs(result->result.elapsed) << "ms";
|
||||
} else {
|
||||
LOG(warning) << "unknown upload image operation: " << info->operation;
|
||||
}
|
||||
LOG_CAT(info, GUI) << Separator;
|
||||
} else if (result == Needmore) {
|
||||
} else {
|
||||
LOG(info) << "UploadImageData status: " << static_cast<uint16_t>(result);
|
||||
LOG(info) << "upload image failed, operation: " << static_cast<uint16_t>(info->operation)
|
||||
<< ", status: " << static_cast<uint16_t>(result);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -93,9 +93,9 @@ public:
|
||||
uint8_t timeout;
|
||||
};
|
||||
|
||||
struct EnrollDataReply {
|
||||
struct EnrollReply {
|
||||
uint16_t userid;
|
||||
uint8_t face_direction; // depleted, user ignore this field
|
||||
uint8_t operation;
|
||||
};
|
||||
|
||||
struct EnrollExtendedReply {
|
||||
@ -146,6 +146,11 @@ public:
|
||||
uint8_t data[0];
|
||||
};
|
||||
|
||||
struct UploadImageReply : public EnrollReply {};
|
||||
struct UploadImageVerifyReply : public UploadImageReply {
|
||||
VerifyReply result;
|
||||
};
|
||||
|
||||
struct ModuleVersion {
|
||||
char version[VersionSize];
|
||||
uint32_t otaVersion;
|
||||
|
@ -173,14 +173,24 @@ Item {
|
||||
TextField {
|
||||
id: imageEnrollName
|
||||
implicitWidth: 100
|
||||
text: "测试下发"
|
||||
}
|
||||
Text {
|
||||
text: qsTr("循环")
|
||||
}
|
||||
Switch {
|
||||
checked: App.imageUploadPersistenceMode
|
||||
onToggled: {
|
||||
App.imageUploadPersistenceMode = checked
|
||||
}
|
||||
}
|
||||
Button {
|
||||
text: "注册"
|
||||
onClicked: App.uploadImage(imagePath.text, 0)
|
||||
onClicked: App.uploadImage(imagePath.text,imageEnrollName.text, 0)
|
||||
}
|
||||
Button {
|
||||
text: "识别"
|
||||
onClicked: App.uploadImage(imagePath.text, 1)
|
||||
onClicked: App.uploadImage(imagePath.text,imageEnrollName.text, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user