更新到HyperLPR3版本
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user