张洋 1 day ago
parent
commit
4f7fc03fbf

+ 5 - 2
zhipuzi_pos_windows/ai/YoloFeatureManager.cpp

@@ -28,6 +28,9 @@ void YoloFeatureManager::loadModel(const std::string & modelPath, const std::str
 
 void YoloFeatureManager::loadClassNames(const std::string & file)
 {
+	//先清空
+	classNames.clear();
+
 	std::ifstream ifs(file);
 	std::string line;
 	while (std::getline(ifs, line))
@@ -109,7 +112,7 @@ std::vector<float> YoloFeatureManager::extractFeatures(const std::string& imageP
 	}
 }
 
-std::vector<float> YoloFeatureManager::Detection(const std::string& imagePath)
+void YoloFeatureManager::Detection(const std::string& imagePath)
 {
 	cv::Mat image = cv::imread(imagePath);
 	if (image.empty())
@@ -203,7 +206,7 @@ void YoloFeatureManager::drawDetection(cv::Mat& img, const std::vector<cv::Rect>
 	// 生成随机颜色(每个类别一种颜色)
 	std::vector<cv::Scalar> colors;
 	srand(time(0));
-	for (int i = 0; i < classNames.size(); i++) {
+	for (std::size_t i = 0; i < classNames.size(); i++) {
 		int r = rand() % 256;
 		int g = rand() % 256;
 		int b = rand() % 256;

+ 2 - 1
zhipuzi_pos_windows/ai/YoloFeatureManager.h

@@ -20,6 +20,7 @@ public:
 	YoloFeatureManager();
 	~YoloFeatureManager() = default;
 
+	// 重新加载模型
 	void loadModel(const std::string & modelPath, const std::string & classesPath);
 	void loadClassNames(const std::string & file);
 
@@ -27,7 +28,7 @@ public:
 	std::vector<float> extractFeatures(const std::string & imagePath);
 
 	// 执行探测
-	std::vector<float> Detection(const std::string& imagePath);
+	void Detection(const std::string& imagePath);
 
 	// 绘制探测结果
 	void YoloFeatureManager::drawDetection(cv::Mat& img, const std::vector<cv::Rect>& boxes, const std::vector<int>& classIds,