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