语义分割C++推断
#pragma once
#include<string>
#include<opencv2/opencv.hpp>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
class _declspec(dllexport)Runtime_Segmentation_new
{
public:
Runtime_Segmentation_new(const std::string model_path_, int image_size_, int num_threads_);
int change_parameters(const std::string model_path_, int image_size_, int num_threads_);
int Runing_infer(std::vector<cv::Mat>&orc_image, std::vector<cv::Mat> & pre_result);
~Runtime_Segmentation_new();
private:
std::string model_path;
int image_size;
int num_threads;
std::string Device;
};
#include "Runtime_Segmentation_new.h"
#include <torch/torch.h>
#include <torch/script.h>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <sstream>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/imgproc/types_c.h>
#include <direct.h>
#include <io.h>
#include <windows.h>
using namespace std;
using namespace cv;
static torch::jit::script::Module model_Segmentation_new;
static torch::Device device_all_Segmentation = torch::kCPU;
static int nw; static int nh;
static void Stringsplit(std::string str, const const char split, vector<std::string>& res)
{
istringstream iss(str);
string token;
while (getline(iss, token, split))
{
res.push_back(token);
}
}
static std::vector<std::string> get_FilePath_many_information(std::string path)
{
std::vector<std::string> information;
const char *file;
file = path.c_str();
char szDrive[_MAX_DRIVE];
char szDir[_MAX_DIR];
char szFname[_MAX_FNAME];
char szExt[_MAX_EXT];
_splitpath(