|
@@ -2,6 +2,9 @@
|
|
|
#include "CDiandanAIShibieWorker.h"
|
|
#include "CDiandanAIShibieWorker.h"
|
|
|
#include "CChengzhongWorker.h"
|
|
#include "CChengzhongWorker.h"
|
|
|
#include "../tool/CAppEnv.h"
|
|
#include "../tool/CAppEnv.h"
|
|
|
|
|
+#include "../ai/SQLiteVecManager.h"
|
|
|
|
|
+#include "CVideoCaptureWorker.h"
|
|
|
|
|
+#include "../tool/CSqlite3.h"
|
|
|
|
|
|
|
|
CDiandanAIShibieWorker::CDiandanAIShibieWorker()
|
|
CDiandanAIShibieWorker::CDiandanAIShibieWorker()
|
|
|
{
|
|
{
|
|
@@ -10,7 +13,7 @@ CDiandanAIShibieWorker::CDiandanAIShibieWorker()
|
|
|
|
|
|
|
|
CDiandanAIShibieWorker::~CDiandanAIShibieWorker()
|
|
CDiandanAIShibieWorker::~CDiandanAIShibieWorker()
|
|
|
{
|
|
{
|
|
|
- int a = 1;
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//启动工作线程
|
|
//启动工作线程
|
|
@@ -18,7 +21,6 @@ void CDiandanAIShibieWorker::StartWork()
|
|
|
{
|
|
{
|
|
|
long int threadId = GetCurrentThreadId();
|
|
long int threadId = GetCurrentThreadId();
|
|
|
|
|
|
|
|
- //默认先关闭
|
|
|
|
|
m_is_work = true;
|
|
m_is_work = true;
|
|
|
|
|
|
|
|
//创建一个新线程,专门处理AI识别的结果,避免因为AI识别的结果处理比较慢,导致界面卡顿
|
|
//创建一个新线程,专门处理AI识别的结果,避免因为AI识别的结果处理比较慢,导致界面卡顿
|
|
@@ -48,7 +50,7 @@ void CDiandanAIShibieWorker::HandleDiandanAIShibie()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
float weight = atof(CChengzhongWorker::GetInstance()->GetWeight().c_str());
|
|
float weight = atof(CChengzhongWorker::GetInstance()->GetWeight().c_str());
|
|
|
- if (weight < 0.01)
|
|
|
|
|
|
|
+ if (weight < -0.01)
|
|
|
{
|
|
{
|
|
|
//说明没有重量,没放东西到秤上面,那么就不识别
|
|
//说明没有重量,没放东西到秤上面,那么就不识别
|
|
|
Sleep(100);
|
|
Sleep(100);
|
|
@@ -58,23 +60,82 @@ void CDiandanAIShibieWorker::HandleDiandanAIShibie()
|
|
|
|
|
|
|
|
auto time_1 = std::chrono::high_resolution_clock::now();
|
|
auto time_1 = std::chrono::high_resolution_clock::now();
|
|
|
|
|
|
|
|
- m_ai_shibie_foodname = YoloFeatureManager::GetInstance()->ClassFromVideoCapture();
|
|
|
|
|
|
|
+ cv::Mat image;
|
|
|
|
|
+ CVideoCaptureWorker::GetInstance()->GetFrame(image);
|
|
|
|
|
+ if (image.empty())
|
|
|
|
|
+ {
|
|
|
|
|
+ //DEBUG_LOG("从摄像头获取帧失败");
|
|
|
|
|
+ Sleep(2000);
|
|
|
|
|
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ m_ai_shibie_foodname = YoloFeatureManager::GetInstance()->Class(image);
|
|
|
if (m_ai_shibie_foodname != "Unknown")
|
|
if (m_ai_shibie_foodname != "Unknown")
|
|
|
{
|
|
{
|
|
|
std::cout << "检测到类别: " << m_ai_shibie_foodname << std::endl;
|
|
std::cout << "检测到类别: " << m_ai_shibie_foodname << std::endl;
|
|
|
|
|
+
|
|
|
|
|
+ m_ai_shibie_foodname = CLewaimaiString::ANSIToUTF8(m_ai_shibie_foodname);
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
std::cout << "未检测到任何类别。" << std::endl;
|
|
std::cout << "未检测到任何类别。" << std::endl;
|
|
|
|
|
+
|
|
|
|
|
+ //开始调用向量数据库检索
|
|
|
|
|
+ if (SQLiteVecManager::GetInstance()->getFeatureCount() > 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ std::vector<float> feature_vector = YoloFeatureManager::GetInstance()->extractFeatures(image);
|
|
|
|
|
+ std::vector<FeatureRecord> searchResults = SQLiteVecManager::GetInstance()->searchSimilarVectors(feature_vector, 5);
|
|
|
|
|
+
|
|
|
|
|
+ if (!searchResults.empty())
|
|
|
|
|
+ {
|
|
|
|
|
+ std::cout << "向量数据库检索结果:" << std::endl;
|
|
|
|
|
+ for (const auto& result : searchResults)
|
|
|
|
|
+ {
|
|
|
|
|
+ std::string food_id = result.foodId;
|
|
|
|
|
+ std::string food_name = result.foodName;
|
|
|
|
|
+ std::string image_name = result.imageName;
|
|
|
|
|
+ std::string image_path = result.imagePath;
|
|
|
|
|
+ float similarity = result.similarity;
|
|
|
|
|
+
|
|
|
|
|
+ std::cout << "食品ID: " << food_id << ", 食品名称: " << food_name << ", 图片名称: " << image_name << ", 图片路径: " << image_path << ", 相似度: " << similarity << std::endl;
|
|
|
|
|
+
|
|
|
|
|
+ CSqlite3 sqlite;
|
|
|
|
|
+
|
|
|
|
|
+ CFood newFood;
|
|
|
|
|
+ bool ret = sqlite.GetFoodById(food_id, newFood);
|
|
|
|
|
+ if (!ret)
|
|
|
|
|
+ {
|
|
|
|
|
+ std::cout << "该相似的商品已被删除" << std::endl;
|
|
|
|
|
+ Sleep(100);
|
|
|
|
|
+
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //UTF8格式,sqlite里面存的都是UTF8格式的字符串
|
|
|
|
|
+ m_ai_shibie_foodname = newFood.name;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ std::cout << "向量数据库中没有相似的特征。" << std::endl;
|
|
|
|
|
+ Sleep(100);
|
|
|
|
|
+
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ std::cout << "向量数据库中没有任何特征。" << std::endl;
|
|
|
|
|
+ Sleep(100);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
auto time_2 = std::chrono::high_resolution_clock::now();
|
|
auto time_2 = std::chrono::high_resolution_clock::now();
|
|
|
|
|
|
|
|
auto duration_1 = std::chrono::duration_cast<std::chrono::milliseconds>(time_2 - time_1);
|
|
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" 毫秒";
|
|
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)
|
|
if (m_hwnd != NULL)
|