C++封装
总体参考文章:https://juejin.im/post/6844903701522415624
现在假设我们的项目实现为两个文件:
需要实现为一个.cpp和一个.h。生成一个DLL项目:
.h文件如下:
#ifdef DETECT_EXPORTS
#define DETECT_API __declspec(dllexport)
#else
#define DETECT_API __declspec(dllimport)
#endif
#include "stdafx.h"
#include <stdlib.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct detect_out {
//预测类型:遥感
string type;
//预测图片的唯一id
string img_id;
//预测的框数量
int pred_box_num;
//预测的框的[xt_cener, y_center, w, h, 置信度]
vector<vector<double>> pred_box;
};
// 此类是从 Win32Project1.dll 导出的
class DETECT_API DETECT {
public:
detect_out DETECT::detection(string img_dir, string img_id, string result_dir, string img_type, int bit_type, int img_channel, int use_gpu);
// TODO: 在此添加您的方法。
};
第一版.cpp文件(调用.bash来调用python tzb.py)如下:
#include "stdafx.h"
#include <stdlib.h>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
#include <cstring>
#include &