| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #include "../pch/pch.h"
- #include "CDiandanAIShibieWorker.h"
- #include "CChengzhongWorker.h"
- #include "../tool/CAppEnv.h"
- CDiandanAIShibieWorker::CDiandanAIShibieWorker()
- {
- }
- CDiandanAIShibieWorker::~CDiandanAIShibieWorker()
- {
- int a = 1;
- }
- //启动工作线程
- void CDiandanAIShibieWorker::StartWork()
- {
- long int threadId = GetCurrentThreadId();
- //默认先关闭
- m_is_work = true;
- //创建一个新线程,专门处理AI识别的结果,避免因为AI识别的结果处理比较慢,导致界面卡顿
- std::thread(&CDiandanAIShibieWorker::HandleDiandanAIShibie, this).detach();
- }
- //结束工作线程
- void CDiandanAIShibieWorker::StopWork()
- {
- m_is_work = false;
- }
- void CDiandanAIShibieWorker::HandleDiandanAIShibie()
- {
- long int threadId = GetCurrentThreadId();
- while (m_is_work == true)
- {
- try
- {
- if (m_is_ai_shibie == false)
- {
- //说明没开启AI识别,就等着
- Sleep(2000);
- continue;
- }
- float weight = atof(CChengzhongWorker::GetInstance()->GetWeight().c_str());
- if (weight < 0.01)
- {
- //说明没有重量,没放东西到秤上面,那么就不识别
- Sleep(100);
- continue;
- }
- auto time_1 = std::chrono::high_resolution_clock::now();
- m_ai_shibie_foodname = YoloFeatureManager::GetInstance()->ClassFromVideoCapture();
- if (m_ai_shibie_foodname != "Unknown")
- {
- std::cout << "检测到类别: " << m_ai_shibie_foodname << std::endl;
- }
- else
- {
- std::cout << "未检测到任何类别。" << std::endl;
- }
- auto time_2 = std::chrono::high_resolution_clock::now();
- auto duration_1 = std::chrono::duration_cast<std::chrono::milliseconds>(time_2 - time_1);
- std::wstring msg = L"all time: " + std::to_wstring(duration_1.count()) + L" 毫秒";
- //DEBUG_LOG(msg.c_str());
- //LOG_INFO(msg);
- //主线程里面去处理界面刷新
- if (m_hwnd != NULL)
- {
- ::PostMessage(m_hwnd, WM_AI_RECOGNITION_SUCCESS, 0, 0);
- }
- }
- catch (const std::exception& e)
- {
- std::string aa = std::string(e.what());
- DEBUG_LOG(("提取特征失败: " + std::string(e.what())).c_str());
- continue;
- }
- }
- //走到这里说明线程要退出了,做一些清理工作
- CAppEnv::GetInstance()->DelWorkerNum();
- }
|