gpt4 book ai didi

c++ - OpenCV LabView 将图像复制到更大的图像

转载 作者:行者123 更新时间:2023-11-28 05:48:16 29 4
gpt4 key购买 nike

几天来我遇到了一个大问题。我在 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)));

最佳答案

已解决的问题:

OpenCV 不像在 LabView 中那样对待矩阵 X、Y(列、行),而是作为行、列!!

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

关于c++ - OpenCV LabView 将图像复制到更大的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35792536/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com