diff --git a/Analyser/CMakeLists.txt b/Analyser/CMakeLists.txt index 4aa1e6f..d33c4ea 100644 --- a/Analyser/CMakeLists.txt +++ b/Analyser/CMakeLists.txt @@ -30,6 +30,7 @@ qt_add_qml_module(Analyser RESOURCES resources/successfull.svg resources/warning.svg + resources/palm-middle.png ) target_compile_definitions(Analyser diff --git a/Analyser/ModuleCommunication.cpp b/Analyser/ModuleCommunication.cpp index 3776d78..655f267 100644 --- a/Analyser/ModuleCommunication.cpp +++ b/Analyser/ModuleCommunication.cpp @@ -1,6 +1,8 @@ #include "ModuleCommunication.h" #include "BoostLog.h" #include "StringUtility.h" +#include +#include #include #include #ifdef WIN32 @@ -257,9 +259,16 @@ void ModuleCommunication::processPackage(const uint8_t *data, uint16_t size) { uint16_t width = ntohs(info->imageWidth); uint16_t height = ntohs(info->imageHeight); userId = ntohs(info->userid); + uint16_t plamX = ntohs(info->palmVeinInformation.x1); + uint16_t plamY = ntohs(info->palmVeinInformation.y1); LOG_CAT(info, GUI) << "注册成功,用户ID: " << userId << ", 图片大小: " << width << "x" << height << ", 已有ID: " << ntohs(info->enrolledId) - << ", 姓名: " << (const char *)info->enrolledUsername; + << ", 姓名: " << (const char *)info->enrolledUsername << ". palm vein: (" + << plamX << "," << plamY << " " << (ntohs(info->palmVeinInformation.x2) - plamX) + << "x" << (ntohs(info->palmVeinInformation.y2) - plamY) + << "), detection probability: " + << ntohs(info->palmVeinInformation.detectionProbability) / 1000.f + << ", quality: " << ntohs(info->palmVeinInformation.quality) / 1000.f; emit newImageInfo(static_cast(replyId), width * height, info->md5); } else { @@ -388,11 +397,15 @@ void ModuleCommunication::processPackage(const uint8_t *data, uint16_t size) { } case NoteId::PalmState: { // 模组返回的数据为当前帧的手掌状态 auto state = reinterpret_cast(data + 6); - uint16_t palmState = ntohs(state->state); + PalmState palmState = static_cast(ntohs(state->state)); if (palmState == NeedMoveToCenter) { emit errorOccurred(NoteId::InteractWarning, "录入提示", "请将手掌置于画面中心"); } else if (palmState == TooFar) { emit errorOccurred(NoteId::InteractWarning, "录入提示", "请将手掌靠近一点"); + } else if (palmState == ManyPalm) { + emit errorOccurred(NoteId::InteractWarning, "录入提示", "检测到多个手掌"); + } else if (palmState == NoAlive) { + emit errorOccurred(NoteId::InteractWarning, "录入提示", "活体检测未通过"); } LOG(info) << "palm state: " << palmState; break; @@ -504,3 +517,15 @@ std::string ModuleCommunication::protocolDataFormatString(const uint8_t *data, i } return oss.str(); } + +BOOST_DESCRIBE_ENUM(ModuleCommunication::PalmState, NoPalm, TooFar, NeedMoveToCenter, ManyPalm, NoAlive) +namespace std { +std::ostream &operator<<(std::ostream &stream, const ModuleCommunication::PalmState &element) { + char const *r = "(unnamed)"; + boost::mp11::mp_for_each>([&](auto D) { + if (element == D.value) r = D.name; + }); + stream << r << "(" << static_cast(element) << ")"; + return stream; +} +} // namespace std diff --git a/Analyser/ModuleCommunication.h b/Analyser/ModuleCommunication.h index 9ec0602..22fd0f1 100644 --- a/Analyser/ModuleCommunication.h +++ b/Analyser/ModuleCommunication.h @@ -59,6 +59,7 @@ public: NoPalm = 1, TooFar = 6, NeedMoveToCenter = 15, + ManyPalm = 101, // 太多掌静脉 NoAlive = 122, }; @@ -112,6 +113,15 @@ public: uint8_t operation; }; + struct PalmVeinInformation { + uint16_t x1; + uint16_t y1; + uint16_t x2; + uint16_t y2; + uint16_t detectionProbability; + uint16_t quality; + }; + struct EnrollExtendedReply { uint16_t userid; uint16_t imageWidth; @@ -120,6 +130,7 @@ public: uint8_t md5[16]; uint8_t enrolledUsername[32]; uint16_t enrolledId; // 掌静脉库里已经存在的id + PalmVeinInformation palmVeinInformation; uint8_t reserved[4]; }; @@ -144,6 +155,7 @@ public: uint16_t image_height; uint8_t image_format; // 0: 只有Y分量,灰度图 uint8_t md5[16]; + PalmVeinInformation palmVeinInformation; }; struct UploadImageInformation { @@ -234,4 +246,8 @@ private: int m_otaVerison; }; +namespace std { +std::ostream &operator<<(std::ostream &stream, const ModuleCommunication::PalmState &element); +} // namespace std + #endif // MODULECOMMUNICATION_H diff --git a/Analyser/resources/palm-middle.png b/Analyser/resources/palm-middle.png new file mode 100644 index 0000000..696eaf7 Binary files /dev/null and b/Analyser/resources/palm-middle.png differ