更新到HyperLPR3版本

This commit is contained in:
tunmx
2023-02-27 15:47:55 +08:00
parent 7ae4d385e1
commit 0864e05f76
912 changed files with 8160 additions and 221461 deletions
@@ -0,0 +1,54 @@
//
// Created by tunm on 2023/2/11.
//
#include "basic_types.h"
#include "../test_settings.h"
#include "opencv2/opencv.hpp"
#include "nn_implementation_module/classification/all.h"
#include "basic_types.h"
#include "utils.h"
using namespace hyper;
TEST_CASE("test_Classification", "[nn_cls]") {
PRINT_SPLIT_LINE
LOGD("[UnitTest]->Classification Model");
std::string model_path = GET_DATA("models/r2_mobile/litemodel_cls_96xh.mnn");
std::vector<std::string> predict_images_list = {
GET_DATA("images/align/1.jpg"),
GET_DATA("images/align/3.jpg"),
GET_DATA("images/align/5.jpg"),
};
std::vector<PlateColor> predict_results_cls = {
PlateColor::BLUE, PlateColor::YELLOW, PlateColor::GREEN,
};
std::vector<float> predict_results_confidence = {
0.9999293f, 0.8975975f, 0.9997952f
};
CHECK(predict_results_confidence.size() == predict_results_cls.size());
CHECK(predict_results_confidence.size() == predict_images_list.size());
ClassificationEngine clsEngine;
auto ret = clsEngine.Initialize(model_path, cv::Size_<int>(96, 96));
CHECK(ret == InferenceHelper::kRetOk);
SECTION("test_ClassificationModelPredict") {
for (int i = 0; i < predict_images_list.size(); ++i) {
cv::Mat img = cv::imread(predict_images_list[i]);
CHECK(!img.empty());
CHECK(img.cols == 96);
CHECK(img.rows == 96);
ret = clsEngine.Inference(img);
CHECK(ret == InferenceHelper::kRetOk);
CHECK(PlateColor(clsEngine.getMOutputColor()) == predict_results_cls[i]);
CHECK(clsEngine.getMOutputMaxConfidence() == Approx(predict_results_confidence[i]).epsilon(0.001));
}
}
}
+46
View File
@@ -0,0 +1,46 @@
//
// Created by tunm on 2023/2/11.
//
#include "basic_types.h"
#include "../test_settings.h"
#include "opencv2/opencv.hpp"
#include "nn_implementation_module/detect/all.h"
#include "basic_types.h"
#include "utils.h"
using namespace hyper;
TEST_CASE("test_Detection", "[nn_detect]") {
PRINT_SPLIT_LINE
LOGD("[UnitTest]->Detect Model");
std::string b_model_path = GET_DATA("models/r2_mobile/b320_backbone_h.mnn");
std::string h_model_path = GET_DATA("models/r2_mobile/b320_header_h.mnn");
cv::Mat test_image_1 = cv::imread(GET_DATA("images/pre.jpg"));
CHECK(test_image_1.cols == 320);
CHECK(test_image_1.rows == 320);
SECTION("test_SplitDetectionSplitModel") {
LOGD("Detect Model SplitModel");
DetArch det;
auto ret = det.Initialize(b_model_path, h_model_path, 320, 1);
CHECK(ret == InferenceHelper::kRetOk);
det.Detection(test_image_1);
auto &result = det.m_results_;
CHECK(result.size() == 1);
auto &box = result[0];
cv::Rect2f proposal_box(cv::Point(153, 205), cv::Point(183, 215));
cv::Rect2f detected_box(cv::Point(box.x1, box.y1), cv::Point(box.x2, box.y2));
auto iou = boundBoxOverlap(proposal_box, detected_box);
CHECK(iou > 0.85);
}
#if ENABLE_BENCHMARK_TEST
SECTION("test_DetectionBenchmark") {
LOGD("[UnitTest]->Detection Benchmark");
}
#endif
}
+51
View File
@@ -0,0 +1,51 @@
//
// Created by tunm on 2023/2/11.
//
#include "basic_types.h"
#include "../test_settings.h"
#include "opencv2/opencv.hpp"
#include "nn_implementation_module/recognition/all.h"
#include "basic_types.h"
#include "utils.h"
using namespace hyper;
TEST_CASE("test_Recognition", "[nn_rec]") {
PRINT_SPLIT_LINE
LOGD("[UnitTest]->Recognition Model");
std::string model_path = GET_DATA("models/r2_mobile/rpv3_mdict_160h.mnn");
std::vector<std::string> predict_images_list = {
GET_DATA("images/rec_crop/_0_津B6H920.jpg"),
GET_DATA("images/rec_crop/_1_皖KD01833.jpg"),
GET_DATA("images/rec_crop/_6_蒙B023H6.jpg"),
GET_DATA("images/rec_crop/_8_冀D5L690.jpg"),
};
std::vector<std::string> predict_results_code = {
"津B6H920", "皖KD01833", "蒙B023H6", "冀D5L690",
};
RecognitionEngine recEngine;
auto ret = recEngine.Initialize(model_path);
CHECK(ret == InferenceHelper::kRetOk);
SECTION("test_SplitDetectionSplitModel") {
LOGD("Rec Model RPV3");
for (int i = 0; i < predict_images_list.size(); ++i) {
cv::Mat img = cv::imread(predict_images_list[i]);
CHECK(!img.empty());
float wh_ratio = (float) img.cols / img.rows;
cv::Mat align_image_pad;
imagePadding(img, align_image_pad, wh_ratio, recEngine.getMInputImageSize());
TextLine line;
ret = recEngine.Inference(align_image_pad, line);
LOGD("%s -> %s", predict_results_code[i].c_str(), line.code.c_str());
CHECK(ret == InferenceHelper::kRetOk);
CHECK(strcmp(predict_results_code[i].c_str(), line.code.c_str()) == 0);
}
}
}
+10
View File
@@ -0,0 +1,10 @@
//
// Created by tunm on 2023/2/11.
//
#define CATCH_CONFIG_RUNNER
#include "test_settings.h"
int main(int argc, char* argv[]) {
return Catch::Session().run(argc, argv);;
}
+21
View File
@@ -0,0 +1,21 @@
//
// Created by tunm on 2023/2/11.
//
#include "test_settings.h"
std::string getTestDataDir() {
return "./resource/";
}
std::string getTestData(const std::string& name) {
return getTestDataDir() + "/" + name;
}
std::string getTestSaveDir() {
return "./resource/save";
}
std::string getTestSaveData(const std::string& name) {
return getTestSaveDir() + "/" + name;
}
+41
View File
@@ -0,0 +1,41 @@
//
// Created by tunm on 2023/2/11.
//
#pragma once
#ifndef ZEPHYRLPR_TEST_SETTINGS_H
#define ZEPHYRLPR_TEST_SETTINGS_H
#include <catch2/catch.hpp>
#include <iostream>
using namespace Catch::Detail;
#define ENABLE_BENCHMARK_TEST 0 // 是否开启性能测试相关用例执行,默认不开启
#define TEST_MSG(...) SPDLOG_LOGGER_CALL(spdlog::get("TEST"), spdlog::level::trace, __VA_ARGS__)
#define GET_DIR getTestDataDir()
#define GET_DATA(filename) getTestData(filename)
#define GET_TMP_DIR getTestSaveDir()
#define GET_TMP_DATA(filename) getTestSaveData(filename)
std::string getTestDataDir();
std::string getTestData(const std::string &name);
std::string getTestSaveDir();
std::string getTestSaveData(const std::string &name);
struct test_case_line {
~test_case_line() {
std::cout
<< "==============================================================================="
<< std::endl;
}
#define PRINT_SPLIT_LINE test_case_line split_line_x;
};
#endif //ZEPHYRLPR_TEST_SETTINGS_H