LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Extracting pointer information in LabVIEW

Hi all,
 
In Intel's OpenCV Image Processing Library (which is entirely written in C/C++), there is a C typedef struct IplImage which is defined as (in condensed form):

typedef struct _IplImage
    {
        int  nSize;         /* sizeof(IplImage) */
        int  ID;            /* version (=0)*/
        int  nChannels;     /* Most of OpenCV functions support 1,2,3 or 4 channels */
        int  alphaChannel;  /* ignored by OpenCV */
        int  depth;         /* pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16U,
                               IPL_DEPTH_16S, IPL_DEPTH_32S, IPL_DEPTH_32F and IPL_DEPTH_64F are supported */
        char colorModel[4]; /* ignored by OpenCV */
        char channelSeq[4]; /* ditto */
        int  dataOrder;     /* 0 - interleaved color channels, 1 - separate color channels.
                               cvCreateImage can only create interleaved images */
        int  origin;        /* 0 - top-left origin,
                               1 - bottom-left origin (Windows bitmaps style) */
        int  align;         /* Alignment of image rows (4 or 8).
                               OpenCV ignores it and uses widthStep instead */
        int  width;         /* image width in pixels */
        int  height;        /* image height in pixels */
    }
    IplImage;

 
There is also a struct cvSize that is defined as:

typedef struct CvSize
    {
        int width; /* width of the rectangle */
        int height; /* height of the rectangle */
    }
    CvSize;

    /* the constructor function */
    inline CvSize cvSize( int width, int height );

 

Now, I used one of OpenCV functions to load an IplImage (ie IplImage *image) and returns a pointer to it. It successfully loads and returns a long integer pointer. 

One of the functions in OpenCV requires the parameter to be the following (written in C):
cvSize(image -> width, image -> height)    
 
How would you represent cvSize(image -> width, image -> height) within LabVIEW? I will need to go to the pointer and extract the width and height information from the pointer.
0 Kudos
Message 1 of 5
(3,260 Views)

hi there

the representation of C/C++ - structures in LabVIEW are Clusters. Create a approbiate cluster containing an I32 "width" and "heigth" and connect it to the dll-node with type "connect to type" and Data format "handles by value" (maybe you have to play around a little bit with these settings). after that you shouls be able to access the elements in the stucture.

you have to be very carefull with the cluster and the structure: the elements must match exactly in their order and size.

best regards & good luck

chris

Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
Message 2 of 5
(3,253 Views)
I guess my real question is:
 
Since I already received the pointer (which is a long integer), how can I go to where the pointer is pointing to and extract the width and height from the memory?
 
I am not using a bundle to pass the IplImage, rather I am using a pointer to pass around the IplImage.
0 Kudos
Message 3 of 5
(3,243 Views)

"Since I already received the pointer (which is a long integer), how can I go to where the pointer is pointing to and extract the width and height from the memory?..."

well, thats exactly the problem: LabVIEW can't work with pointers like C, you only can access the 4 bytes of memory allocated by the long integer. the memory "after" that pointer can't be accessed directly with labview. you need to allocate a buffer managed by the LabVIEW RTE large enough to hold the whole data and with the correct memory alignmend (the cluster i mentioned) and pass the pointer to that buffer to the dll with the options mentioned above. the data will then be written to that buffer and you are then able to access the data in the cluster inside the LabVIEW RTM.

I think there are some API - functions in user32.dll or kernel32.dll to access memory directly, but that's something to do on a long dark winter day...

(if i said something wrong pls let me know..)

best regards

chris

 

 

 

Best regards
chris

CL(A)Dly bending G-Force with LabVIEW

famous last words: "oh my god, it is full of stars!"
0 Kudos
Message 4 of 5
(3,232 Views)
While it is correct that LabVIEW cannot access the data at a pointer location, it has no trouble retrieving data from a C function by reference.  So, if you have a C functiion call in a DLL which returns your data by value or reference (in the variables, LabVIEW only handles strings and simple numerics as the function return value), it can be accessed by LabVIEW using the call library node, provided your cluster representation is exactly correct.  Check out the LabVIEW examples of calling DLLs using the call library node for more information.
0 Kudos
Message 5 of 5
(3,216 Views)