写了一个基于opencv的算法,会用到opencv的Net、Mat等类型和函数,大概是几个个接口用来接受参数路径,把读取net放在了循环之外因此private中含有Net类型,参考了dllexport但是头文件类的声明有mat、net存在仍然需要拷贝opencv的所有东西和环境
现需要使用ocr::rec函数以及读取模型的readmodel函数,输入图像返回运算图像
将它打包成一个dll交付给他人使用应该如何做到,纯虚函数是否可行,请教具体方法?
目前头文件如下
#pragma once
#ifdef _DLL_EXPORTS
#define DLL_API _declspec(dllexport)
#else
#define DLL_API _declspec(dllimport)
#endif
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <opencv2/opencv.hpp>
#include <opencv2/dnn.hpp>
#include <opencv2/dnn/all_layers.hpp>
#include <string>
#include <vector>
#include <algorithm>
#include <array>
#include<cmath>
#include<windows.h>
#ifndef INTERFACE_DEFINE_AND_REALIZE
#define INTERFACE_DEFINE_AND_REALIZE
#include <string>
using std::string;
//define interface
using namespace std;
using namespace cv;
using namespace dnn;
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; //此处为opencv的net类型
int rect_thresh = 0;
int blocksize = 31;
int C = 10;
int left = 0;
int right = 0;
int up = 0;
int down = 0;
int softmax_thresh;
//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;
}
void set_C(int x)
{
C = x;
}
void set_canny_max(int x)
{
canny_max = x;
}
void set_abcd(int x, int y, int z, int f)
{
up = x;
down = y;
left = z;
right = f;
}
void set_min_width(int x)
{
min_width = x;
}
void set_softmax_thresh(int x)
{
softmax_thresh = x;
}
void load_model(const string model_path, Net &net);//Net net
void char2mat(unsigned char* cimg, Mat &mat, int h, int w, int channel);
void rotate(Mat &frame);
void undistort(Mat &frame);
void find_rect(cv::Mat& frame, Mat &dst, Point &startpoint, int rect_thresh, int rect_morph_x = 1, int rect_morph_y = 1, int operation = 0, int erosion_elem = 0, int iteration = 1);
void getthresh(Mat &frame, int thresh1, int thresh3, int bitwise_mode = 0, int thresh_mode = 0, int blocksize = 35, int C = 29, int i = 7);
void canny_crop(Mat &frame, Mat &output, vector<int>&result, vector<double>&softmax, int &flag2, Net net, vector<Rect> &digit_rect, int bitwise_mode2, int morph_x = 1, int morph_y = 9, //9
int iteration = 1, int padding = 0, int canny_max = 300);
void vertical_crop(Mat &frame);
//blobfromimages
void rec_single(Mat &img, int &num, float &prob, int &flag2, Net net, float scale = 1.0 / 255);
void findSquares(Mat &frame, Mat &out);
void SortRotatedRectPoints(Point2f vetPoints[], RotatedRect &rect, int flag);
//void thinimage(Mat &srcimage);
void thinimage(Mat &input_src, Mat & output_dst, int number = 1);
Mat ImgSkeletonization_H(Mat &input_src, int *search_arr);
Mat ImgSkeletonization_V(Mat &input_src, int *search_arr);
//int morph_x, int morph_y, a, b, c, d;
void rec(Mat &frame, Mat &output, Mat &canny_crop, Mat &rect_crop);
void crec(unsigned char *input, unsigned char *output, unsigned char *rect, unsigned char *threshold, unsigned char *canny);//gauss置于morph后
};
#endif