LabVIEWForum.de
Problem Image from OpenCV to LabView - Druckversion

+- LabVIEWForum.de (https://www.labviewforum.de)
+-- Forum: LabVIEW (/Forum-LabVIEW)
+--- Forum: LabVIEW Module (/Forum-LabVIEW-Module)
+---- Forum: LabVIEW Vision (/Forum-LabVIEW-Vision)
+---- Thema: Problem Image from OpenCV to LabView (/Thread-Problem-Image-from-OpenCV-to-LabView)



Problem Image from OpenCV to LabView - Xeno1987 - 25.02.2016 13:52

Hello,

I think that there is a memory alloc problem, hope you can help me.

Code:
#include <windows.h>
#include <extcode.h>
#include <iostream>
#include <stdio.h>
#include "opencv2/core.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"

using namespace cv;
using namespace std;

// --- 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(short* M, short* N, short* image, int SizeX, int SizeY, short* imgOut){

    // Alloc Memory
    Mat imgIn(SizeX, SizeY, CV_16S, &image[0]);
    Mat imOut(SizeX, SizeY, CV_16S, &imgOut[0]);
    
    
    // Clone Source Image
    
    imOut = imgIn.clone();
    
    
    // Get size for DFT
    *M = getOptimalDFTSize(imgIn.rows);
    *N = getOptimalDFTSize(imgIn.cols);
return 0;
}



#ifdef __cplusplus
}
#endif  /* __cplusplus */


VI Module:

http://postimg.org/image/awk7zj8yb
http://postimg.org/image/riz35ukux


RE: Problem Image from OpenCV to LabView - Freddy - 08.03.2016 14:12

In der Community von NI wurde diese Frage gestellt:

Create a DLL to Read an Image Using OpenCV

Als Antwort kam der Link:

Community NI

Vielleicht hilft es Dir weiter.

Gruß
Freddy


RE: Problem Image from OpenCV to LabView - rolfk - 11.03.2016 13:58

(25.02.2016 13:52 )Xeno1987 schrieb:  Hello,

I think that there is a memory alloc problem, hope you can help me.

__declspec(dllexport) INT myDoSomething(short* M, short* N, short* image, int SizeX, int SizeY, short* imgOut){

// Alloc Memory
Mat imgIn(SizeX, SizeY, CV_16S, &image[0]);
Mat imOut(SizeX, SizeY, CV_16S, &imgOut[0]);


// Clone Source Image

imOut = imgIn.clone();

// Get size for DFT
*M = getOptimalDFTSize(imgIn.rows);
*N = getOptimalDFTSize(imgIn.cols);
return 0;
}

Natürlich! Die rot angemerkte Linie kann niemals funktionieren. Das Funktionsinterface ist C, nicht C++ und deshalb kannst Du auch keine C++ automatic pointers verwenden wie das neuere Versionen von OpenCV unterstützen.

Du musst in LabVIEW sicher stellen dass der Buffer für imgOut alloziert wird (wenn es ein IMAQ image ist musst Du den Datentyp und die Höhe und Breite setzen und dann den Pointer auf das Image übergeben. Im C code darfst Du nicht einen neuen Speicher allozieren, was img.clone() macht, sondern musst Du die Pixels korrekt in diesen Buffer kopieren.