Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Class Mat图像的向量在传输到类后发生更改_Class_Opencv_Dll_Vector - Fatal编程技术网

Class Mat图像的向量在传输到类后发生更改

Class Mat图像的向量在传输到类后发生更改,class,opencv,dll,vector,Class,Opencv,Dll,Vector,我有一个奇怪的问题,在dll中的类和主应用程序之间进行通信后,会导致缺少变量。主应用程序将8个Mat图像加载到一个向量中,然后调用库dll对其进行处理 以下是主要的应用程序代码: int ReturnCode = 0; HINSTANCE DLLCALL = LoadLibrary(L"IMAGEPROC.dll"); Interface_factory factoryFunc = reinterpret_cast<Interface_factory>(::GetProcAdd

我有一个奇怪的问题,在dll中的类和主应用程序之间进行通信后,会导致缺少变量。主应用程序将8个Mat图像加载到一个向量中,然后调用库dll对其进行处理

以下是主要的应用程序代码:

int ReturnCode = 0;

HINSTANCE DLLCALL = LoadLibrary(L"IMAGEPROC.dll");


Interface_factory factoryFunc = reinterpret_cast<Interface_factory>(::GetProcAddress(DLLCALL, "CreateCOGInterfaceObject"));

if (!factoryFunc) {
    ReturnCode = ERROR_UNABLETOLOADLIBRARY;

    ::FreeLibrary(DLLCALL);

    return ReturnCode;
}

COGInterface* cog = factoryFunc();


ReturnCode = Commitment(argc, argv, cog);


FreeLibrary(DLLCALL);

return ReturnCode;
在承诺中:

vector<Mat>vectorImages;    
for (int i = 0; i < NumFiles; i++) {
        string FileTemp = "";
        FileTemp.append(LastFileStatus);
        FileTemp.append(to_string(i));
        FileTemp.append(FileExtension);

        bool FileCheck = FileExistenceCheck(FileTemp.data());

        if (!FileCheck)
            return ERROR_IMAGEFILENOTEXIST;


        vectorImages.push_back(imread(FileTemp));   

}

cog->VariableTransfer(vectorImages);
下面是DLL中的接口类:

class COGInterface
{
public:
    virtual ~COGInterface() {};

public:
    virtual int ImageLoader(Mat &image) = NULL;
    virtual int VariableTransfer(vector<cv::Mat> vimage) = NULL;
};

   // And this is the hidden class in the same DLL:

class COGDLL : public COGInterface {

 public:
    COGDLL() {}
    ~COGDLL() {}

    void destroy() {delete this;}

        public:
            vector<string> strReport;
            vector<cv::Mat> vectorImages;

            Mat OriginalImage;
            Mat GrayImage;
            Mat RoIImage;
            Mat tPatternImage;
            Mat bPatternImage;

            int NumberofFiles;

            int ImageLoader(Mat &image);
            int MainProcess(Mat &image);
            int Preprocess(Mat &image);

            int VariableTransfer(vector<cv::Mat> vimage);
        };

        int COGDLL::ImageLoader(Mat &image)
        {


            imshow("test", image);
            waitKey(0);

            return 0;
        }


        int COGDLL::VariableTransfer(vector<Mat> loasters)
        {
            vectorImages.swap(loasters);

            imshow("Testers", vectorImages[0]);

            waitKey(0);

            return 0;
        }

        extern "C" __declspec(dllexport) COGInterface* __cdecl CreateCOGInterfaceObject()
        {
            return new COGDLL;
        }
在我开始转移向量之前,我检查了向量中的图像是否都正常,但在那之后,它完全改变了,向量看起来根本没有相同的图像

左:转移前,右:转移后

如何使类从主应用程序接收相同的向量?
谢谢

如果您在int MainProcessMat&image或int prepreprocessmat&image中做了任何更改,请确保您在其副本上做了更改,例如image.clone,如果您不想更改原始图像。这些函数中没有实现。我刚刚将向量从main传输到DLL中的类。在转移之后,它看起来好像丢失了。