现有一个依赖opencv的算法,类成员函数可实现输入输出,但参数中含有mat,private中含有net类型,头文件因此无法摆脱opencv依赖,问:现欲摆脱opencv的头文件和dll依赖,将该dll交付他人使用,是否可以做到将头文件写进cpp中,直接无头文件或者写个头文件接口直接dll和lib调用该类中的算法,以及修改接口中的私有变量参数
class _declspec(dllexport) ocr
{
private:
int crop_mode = 1;
int thresh_mode=1;
int bitwise_mode2 = 0;
double blur1 = 3;
double blur2 = 11;
//int rect_morph_x;
//int rect_morph_y;
int morph_x = 1;
int morph_y = 9;
int iteration = 1;
int canny_max = 300;
int min_width = 8;
int i;//高斯模糊
int flag;
int flag2;
string model_path = "./1.onnx";
Net net;
int rect_thresh = 0;
int blocksize = 31;
int C = 10;
int a = 3;
int c = 5;
int b = -5;
int d = 10;
int softmax_thresh=0.9;
//block,C,threshold
//unsigned char * img
public:
//void ~ocr(){}
//inline
void set_morph(int x, int y, int iter)
{
morph_x = x;
morph_y = y;
iteration = iter;
}
void set_blocksize(int x)
{
blocksize = x;
}
//inline
void set_net(string model_path)
{
net = cv::dnn::readNetFromONNX(model_path);
}
void set_rect_thresh(int x)
{
rect_thresh = x;
}
都已经告诉过你了,你不使用的话,也没有其它办法了,隐藏其它依赖dll,确确实实只能那样做,如果你嫌动态加载资源中的dll麻烦,你也可以把资源里的dll偷偷的复制到system32那里。动态复制,就是dllmain执行的时候检查有没有OpenCV的相关dll,没有再复制过去。或者找OpenCV的源码一起编译进去是最好的啦。
摆脱opencv的头文件或者dll?那就相当于没用opencv这个库了。不用头文件的话你怎么调用opencv里面的方法?dll是opencv的动态库,你也可以选择使用静态库在生成的时候就将它编译链接到你的项目里面。
你的问题解决了没有了?没有的话继续讨论呢。
我尝试了加入所有的lib静态库,但是头文件还是需要include opencv.hpp
搞那么复杂干什么,直接头文件里不用opencv的类型就可以了,那就啥头文件都没有了。
用指针替代opencv的类型,在封装的cpp文件里,增加需要用到的第三方头文件。
写个简单例子吧,
.h文件里opencv啥类型都不加,
void test(const char* ImgBuf, int width, int height, int channel );
.cpp文件里实现:
void test(const char* ImgBuf, int width, int height, int channel )
{
Mat srcImage = Mat(height, width, CV_MAKETYPE(CV_8U, channel), (void*)ImgBuf);
}
这样就转换成你需要的Mat类型了,而且头文件里没有Mat类型。第三方头文件放在cpp里,就不影响你要的要求了。