更新到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
+75
View File
@@ -0,0 +1,75 @@
//
// Created by tunm on 2023/1/26.
//
#include <iostream>
#include "hyper_lpr_sdk.h"
#include "opencv2/opencv.hpp"
static const std::vector<std::string> TYPES = {"蓝牌", "黄牌单层", "白牌单层", "绿牌新能源", "黑牌港澳", "香港单层", "香港双层", "澳门单层", "澳门双层", "黄牌双层"};
int main(int argc, char **argv) {
char *model_path = argv[1];
char *image_path = argv[2];
cv::Mat image = cv::imread(image_path);
// create ImageData
HLPR_ImageData data = {0};
data.data = image.ptr<uint8_t>(0);
data.width = image.cols;
data.height = image.rows;
data.format = STREAM_BGR;
data.rotation = CAMERA_ROTATION_0;
// create DataBuffer
P_HLPR_DataBuffer buffer = HLPR_CreateDataBuffer(&data);
// create context
HLPR_ContextConfiguration configuration = {0};
configuration.models_path = model_path;
configuration.max_num = 5;
configuration.det_level = DETECT_LEVEL_LOW;
configuration.use_half = false;
configuration.nms_threshold = 0.5f;
configuration.rec_confidence_threshold = 0.5f;
configuration.box_conf_threshold = 0.30f;
configuration.threads = 1;
P_HLPR_Context ctx = HLPR_CreateContext(&configuration);
HREESULT ret = HLPR_ContextQueryStatus(ctx);
if (ret != HResultCode::Ok) {
printf("create error.\n");
return -1;
}
// exec plate recognition
HLPR_PlateResultList results = {0};
double time;
time = (double)cv::getTickCount();
HLPR_ContextUpdateStream(ctx, buffer, &results);
time = ((double)cv::getTickCount() - time) / cv::getTickFrequency();
printf("cost: %f\n", time);
for (int i = 0; i < results.plate_size; ++i) {
std::string type;
if (results.plates[i].type == HLPR_PlateType::PLATE_TYPE_UNKNOWN) {
type = "未知";
} else {
type = TYPES[results.plates[i].type];
}
cv::rectangle(image, cv::Point2f(results.plates[i].x1, results.plates[i].y1), cv::Point2f(results.plates[i].x2, results.plates[i].y2),
cv::Scalar(100, 100, 200), 3);
printf("<%d> %s, %s, %f\n", i + 1, type.c_str(),
results.plates[i].code, results.plates[i].text_confidence);
}
// cv::imwrite("out.jpg", image);
cv::imshow("out", image);
cv::waitKey(0);
// release buffer
HLPR_ReleaseDataBuffer(buffer);
// release context
HLPR_ReleaseContext(ctx);
return 0;
}
+47
View File
@@ -0,0 +1,47 @@
//
// Created by tunm on 2023/1/22.
//
#include <iostream>
#include "opencv2/opencv.hpp"
#include "context_module/all.h"
#include "buffer_module/all.h"
using namespace hyper;
static const std::vector<std::string> TYPES = {"蓝牌", "黄牌单层", "白牌单层", "绿牌新能源", "黑牌港澳", "香港单层", "香港双层", "澳门单层", "澳门双层", "黄牌双层"};
int main(int argc, char **argv) {
char *model_path = argv[1];
char *image_path = argv[2];
cv::Mat image = cv::imread(image_path);
HyperLPRContext context;
auto ret = context.Initialize(model_path, 5, DetectLevel::DETECT_LEVEL_LOW);
if (ret != hRetOk) {
LOGE("Load error.");
return -1;
}
CameraBuffer buffer;
buffer.SetDataBuffer(image.data, image.rows, image.cols);
buffer.SetDataFormat(BGR);
buffer.SetRotationMode(ROTATION_0);
double time;
time = (double)cv::getTickCount();
context(buffer);
time = ((double)cv::getTickCount() - time) / cv::getTickFrequency();
LOGD("pipeline cost: %f", time);
auto &objs = context.getMObjectResults();
for (auto &obj: objs) {
cv::rectangle(image,
cv::Point2f(obj.x1, obj.y1),
cv::Point2f(obj.x2, obj.y2),
cv::Scalar(0, 0, 200),
2);
LOGD("[%s]%s", TYPES[obj.type].c_str(), obj.code);
LOGD("文本均值置信度: %f", obj.text_confidence);
}
cv::imshow("w", image);
cv::waitKey(0);
return 0;
}
+113
View File
@@ -0,0 +1,113 @@
//
// Created by Tunm-Air13 on 2023/2/8.
//
#include <iostream>
#include "opencv2/opencv.hpp"
//#include "loader_module/all.h"
#include "nn_implementation_module/all.h"
#include "configuration.h"
using namespace hyper;
int main(int argc, char **argv) {
char *model_path = argv[1];
char *image_path = argv[2];
int input_size = 320;
std::string backbone_path = std::string(model_path) + "/" + hyper::DETECT_LOW_BACKBONE_FILENAME;
std::string head_path = std::string(model_path) + "/" + hyper::DETECT_LOW_HEAD_FILENAME;
// std::string backbone_path = std::string(model_path) + "/" + hyper::DETECT_HIGH_BACKBONE_FILENAME;
// std::string head_path = std::string(model_path) + "/" + hyper::DETECT_HIGH_HEAD_FILENAME;
// int input_size = 640;
cv::Mat image = cv::imread(image_path);
// DetBackbone backbone;
// backbone.Initialize(backbone_model);
//
// DetHeader header;
// header.Initialize(header_model);
//
//
// backbone.Inference(image);
//
// header.Inference(backbone.getMOutputTensorInfoList()[0].GetDataAsFloat(),
// backbone.getMOutputTensorInfoList()[1].GetDataAsFloat(),
// backbone.getMOutputTensorInfoList()[1].GetDataAsFloat());
// for (int i = 0; i < 20; ++i) {
// std::cout << header.getMOutputTensorInfoList()[0].GetDataAsFloat()[i] << std::endl;
// }
// float *h = header.getMOutputTensorInfoList()[0].GetDataAsFloat();
// for (int i = 0; i < 6300 * 15; ++i) {
//// std::cout << backbone.m_output_feature_map_40p_.get()[i] << std::endl;
// FILE *fp = NULL;
// fp = fopen("head.txt", "a");
// fprintf(fp, "%f\n", h[i]);
// fclose(fp);
// }
//
// float *p40 = backbone.getMOutputTensorInfoList()[0].GetDataAsFloat();
// for (int i = 0; i < 45 * 40 *40; ++i) {
//// std::cout << backbone.m_output_feature_map_40p_.get()[i] << std::endl;
// FILE *fp = NULL;
// fp = fopen("40.txt", "a");
// fprintf(fp, "%f\n", p40[i]);
// fclose(fp);
// }
//
// std::cout << std::endl;
// float *p20 = backbone.getMOutputTensorInfoList()[1].GetDataAsFloat();
// for (int i = 0; i < 45 * 20 * 20; ++i) {
//// std::cout << backbone.m_output_feature_map_20p_.get()[i] << std::endl;
// FILE *fp = NULL;
// fp = fopen("20.txt", "a");
// fprintf(fp, "%f\n", p20[i]);
// fclose(fp);
// }
// std::cout << std::endl;
// float *p10 = backbone.getMOutputTensorInfoList()[2].GetDataAsFloat();
// for (int i = 0; i < 45 * 10 * 10; ++i) {
//// std::cout << backbone.m_output_feature_map_10p_.get()[i] << std::endl;
// FILE *fp = NULL;
// fp = fopen("10.txt", "a");
// fprintf(fp, "%f\n", p10[i]);
// fclose(fp);
// }
DetArch arch;
arch.Initialize(backbone_path, head_path, input_size);
double time;
time = (double)cv::getTickCount();
arch.Detection(image, true);
time = ((double)cv::getTickCount() - time) / cv::getTickFrequency();
auto &results = arch.m_results_;
for (auto &plate : results) {
std::cout << plate.x1 << ", " << plate.y1 << std::endl;
cv::rectangle(image, cv::Point2f(plate.x1, plate.y1), cv::Point2f(plate.x2, plate.y2),
cv::Scalar(100, 100, 200), 1);
for (int i = 0; i < 4; ++i) {
cv::line(image, cv::Point2f(plate.kps[i * 2 + 0], plate.kps[i * 2 + 1]),
cv::Point2f(plate.kps[i * 2 + 0], plate.kps[i * 2 + 1]), cv::Scalar(100, 220, 20), 1);
}
}
#ifdef BUILD_LINUX_ARM7
cv::imwrite("out.jpg", image);
#else
cv::imshow("w", image);
cv::waitKey(0);
#endif
return 0;
}