OpenCV LabView将图像复制到更大的图像

时间:2016-03-04 09:36:16

标签: c++ opencv labview

有些日子我有一个大问题。我在LabView中创建了一个大小为4096x4096的空图像,并希望在OpenCV中将较小的图像复制到它。 结果我每次都会得到一张黑色图像。

Mat imgIn = Mat(SizeX, SizeY, CV_16U, &image[0]);          // Small pic
Mat imOut = Mat(4096, 4096, CV_16U, &imgOut[0]);

imgIn.copyTo(imOut(Rect(500, 500, imgIn.size().width, imgIn.size().height)));

for(int i = 0;i < 4096;i++){
    for(int j = 0;j < 4096;j++){

         if((imOut.data[i,j])>300) *test += 1;
         *imgOut++ = imOut.data[i,j];
    } 
}

这是我在Labview的新VI:

我的结果:

更新:更新后的代码:

Mat imgIn = Mat(SizeX, SizeY, CV_16U, &image[0]);          // Small pic
Mat imOut = Mat(4096, 4096, CV_16U, &imgOut[0]);

imgIn.copyTo(imOut(Rect(500, 500, imgIn.size().width, imgIn.size().height)));

图:

更新2代码:

// --- Dll entry point ---
 BOOL APIENTRY DllMain( HANDLE hModule, 
                   DWORD  ul_reason_for_call, 
                   LPVOID lpReserved
                 )
{
UNREFERENCED_PARAMETER(hModule);
UNREFERENCED_PARAMETER(lpReserved);
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
    break;
}
return TRUE;
}


#ifdef __cplusplus
extern "C" {
#endif  /* __cplusplus */


__declspec(dllexport) INT myDoSomething(unsigned int *test, unsigned short *image, int SizeX, int SizeY, unsigned short *imgOut){

// Alloc Memory
Mat imgIn = Mat(SizeX, SizeY, CV_16U, &image[0]);          // Small pic
Mat imOut = Mat(4096, 4096, CV_16U, &imgOut[0]);           // Big pic

imgIn.copyTo(imOut(Rect(1000, 1000, imgIn.size().width, imgIn.size().height)));

1 个答案:

答案 0 :(得分:1)

解决问题:

OpenCV将矩阵视为不像Lab,X,Y(列,行),而是行,列!!

Mat imgIn = Mat(SizeY, SizeX, CV_16UC1, &image[0]);