重复识别
parent
e388c5a8eb
commit
e7cb901478
|
@ -18,7 +18,7 @@ namespace zsy
|
|||
GenericBarrier::GenericBarrier(const BarrierProperties &config)
|
||||
: config(config)
|
||||
{
|
||||
Application::eventManager->subscribe(config.sn + "/open", [this](const EventManager::Event&)
|
||||
Application::eventManager->subscribe(config.sn + "/open", [this](const EventManager::Event &)
|
||||
{
|
||||
this->open();
|
||||
});
|
||||
|
@ -48,6 +48,8 @@ namespace zsy
|
|||
|
||||
Application::httpSvr->postEndpoint("/plateRecognize", [](const httplib::Request &req, httplib::Response &res)
|
||||
{
|
||||
static std::unordered_map<std::string, long long> cache;
|
||||
static std::mutex cacheMutex;
|
||||
try
|
||||
{
|
||||
auto body = req.body;
|
||||
|
@ -75,6 +77,26 @@ namespace zsy
|
|||
res.set_content(R"({})", "application/json");
|
||||
return;
|
||||
}
|
||||
auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||
auto key = serialno + license;
|
||||
long long time = ms + 60000 * 5;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(cacheMutex);
|
||||
std::erase_if(cache, [time](const auto &pair)
|
||||
{
|
||||
return pair.second >= time;
|
||||
});
|
||||
if (cache.contains(key))
|
||||
{
|
||||
if (cache[key] < time)
|
||||
{
|
||||
res.set_content(R"({})", "application/json");
|
||||
LOGGER_INFO("重复的车牌识别结果:{} {}", serialno, license);
|
||||
return;
|
||||
}
|
||||
}
|
||||
cache[key] = ms;
|
||||
}
|
||||
|
||||
Application::threadPool->submit([imageFile,license, barrier = Application::deviceHolder->getBarrier(serialno)]
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue