I searched in my new C ++, but unfortunately there is information on how I can integrate the following function using the external “C” declspec (dllexport) and call this function in C ++. I did.
extern "C" declspec(dllexport) std::vector<std::vector<double>> cdecl PrepareFaceBank(std::string Path)
But unfortunately I received the following error, I have no idea, thank you very much for your help?
extern "C" declspec(dllexport) std::vector<std::vector<double>> cdecl PrepareFaceBank(std::string Path)
{
try
{
//load model (if it has been loaded any where else just comment it)
FaceModule = torch::jit::load(FaceModulePath);
std::cout << "Model loaded successfully" << std::endl;
//Disable grad for high performance beacuase this is pretrained model
torch::NoGradGuard no_grad;
//an array to save all persons tensor in it
std::vector<torch::Tensor> embeddings;
//itterate through facebank directory
for (const auto& name : get_folderPath(Path))
{
std::cout << "name :" << name.filename() << ": " << '\n';
//array to save all of the photos of each person
std::vector<torch::Tensor> embs;
//clear befor itterate through all photos of each person
embs.clear();
//int a = 0;
for (const auto& fileName : get_filenames(name))
{
//std::cout <<'\t' << fileName << std::endl;
Mat image = imread(fileName);
/* Display if needed:
cv::namedWindow("Display window");// Create a window for display.
cv::imshow("Display window", image);
cv::waitKey(0);
*/
embs.push_back(ProcessFrame(image));
//empty cache
image.release();
//how many photos each person have
//std::cout << '\t' << a++ << std::endl;
}
//number of photos in data base for this person
//std::cout << "embs size: " << embs.size() << "\n";
//convert vector to tensorlist and the calculate the Mean value for all of the photos of each person
torch::Tensor embedding; // 1*512
torch::TensorList tensor_list{ embs };
embedding = torch::mean(torch::cat(tensor_list), 0);
embeddings.push_back(embedding);
}
std::vector<double> EachPersonVec;
std::vector<std::vector<double> > retValue;
for (const auto& n : embeddings)
{
EachPersonVec.clear();
for (int i = 0; i < 512; i++)
{
EachPersonVec.push_back(n[i].item().to<double>());
}
retValue.push_back(EachPersonVec);
}
//number of persons in database
std::cout << "embeddings size : " << embeddings.size() << "\n";
return retValue;
}
catch (const std::exception& e)
{
std::cout << e.what() << std::endl;
}
}
Severity Code Description Project File Line Suppression State
Error C2526 'PrepareFaceBank': C linkage function cannot return C++ class 'std::vector<std::vector<double,std::allocator<double>>,std::allocator<std::vector<double,std::allocator<double>>>>' detect-camera-demo D:\Project\Face\libfacedetection\example\Trian.cpp 67