上个问题因信息提供不足结题,重新发布:
编写LIb过程中,出现了std类型返回值 无法导出lib传递的问题。
假如我想在exe中接收ocr_results返回值。
但是std无法跨dll或lib,请给出三种高效的解决方案,并举出简洁示例。使我能传递std类型返回值
答案满足要求即采纳。
lib中的代码如下:包括结构体:
//涉及到的结构体:
struct OCRPredictResult {
std::vector<std::vector<int>> box;
std::string text;
float score = -1.0;
float cls_score;
int cls_label = -1;
};
struct StructurePredictResult {
std::vector<float> box;
std::vector<std::vector<int>> cell_box;
std::string type;
std::vector<OCRPredictResult> text_res;
std::string html;
float html_score = -1;
float confidence;
};
//导出函数的代码
std::vector<std::vector<OCRPredictResult>> processImagesOcr(PPOCR& ocrInstance, const OCRFlags& flags) {
check_params();
if (!Utility::PathExists(flags.image_dir)) {
std::cerr << "[ERROR] image path not exist! image_dir: " << flags.image_dir
<< std::endl;
exit(1);
}
std::vector<cv::String> cv_all_img_names;
cv::glob(flags.image_dir, cv_all_img_names);
if (!Utility::PathExists(flags.output)) {
Utility::CreateDir(flags.output);
}
if (flags.benchmark) {
ocrInstance.reset_timer();
}
std::vector<cv::Mat> img_list;
std::vector<cv::String> img_names;
for (int i = 0; i < cv_all_img_names.size(); ++i) {
cv::Mat img = cv::imread(cv_all_img_names[i], cv::IMREAD_COLOR);
if (!img.data) {
std::cerr << "[ERROR] image read failed! image path: "
<< cv_all_img_names[i] << std::endl;
continue;
}
img_list.push_back(img);
img_names.push_back(cv_all_img_names[i]);
}
std::vector<std::vector<OCRPredictResult>> ocr_results =
ocrInstance.ocr(img_list, flags.det, flags.rec, flags.cls);
if (flags.benchmark) {
ocrInstance.benchmark_log(cv_all_img_names.size());
}
return ocr_results;
}
主函数中代码如下
//加载 链接lib省略
std::vector<std::vector<OCRPredictResult>> predictResults =processImagesOcr();