Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

IMAGE PROCESSING THROUGH DLL WRITTEN IN C++

Hello,,,

actually i am writing a program for image processing in c++ and try to make a DLL . My idea is to use labview for acquiring and displaying the images and use c++ for calculation because i think if i use dll the time will be shorter than using labview VI's... i succeed in obtaining results,,, but the processing time became longer than using labview VI's for processing.... This problem occurs from using the image 2d array in the following style:

for (j = 0; j < row; j++)
{

   for (i = 0; i < col; i++)
          {

 

                   A[j*col + i] = a[j*col + i];

            }
        }

}

 

because of the consideration of memory allocation....

 

My question is: how can i use the image 2d array as same in c++.... I mean how to write it in this form A[j][ i] using pointer without make confusing labview memory...

 

thanks,,,

0 Kudos
Message 1 of 11
(6,949 Views)

Hello M.A.A.M,

 

I am attaching the DLL, C++ source code and Labview VI that uses the DLL to add some manual constant to 8-bit image using pointers.

 

Hope it helps you.

 

Best regards,

K


https://decibel.ni.com/content/blogs/kl3m3n



"Kudos: Users may give one another Kudos on the forums for posts that they found particularly helpful or insightful."
0 Kudos
Message 2 of 11
(6,937 Views)

I forgot to add some comments to the previous post:

 

As far as i know, a lot of libraries in labview are written in c++ an c. So, i don't think you will see very much performance gain when comparing the built-in functions to other functions in let's say OpenCV. I always wanted to know if labview uses OpenCV libraries, since there is some reference to it in the documentation? If you will be using your custom functions, you should have some experience to write clean, memory nonleak code.

 

The second comment is that you should use vectors instead of arrays in c++ as it is (in my opinion) easier to manipulate with. 2D array is just a representation. The values that are written in memory more resemble the "vector pattern". So, incrementing the pointer, moves to the next block in memory space (depends on the variable type).

 

Best regards,

K

 

 


https://decibel.ni.com/content/blogs/kl3m3n



"Kudos: Users may give one another Kudos on the forums for posts that they found particularly helpful or insightful."
0 Kudos
Message 3 of 11
(6,932 Views)

thanks sir,, i will try and inform you by the results,,, thanks again...

0 Kudos
Message 4 of 11
(6,924 Views)

unfortunatily iam using labview 2009,,, please can you attach an the block diagram as print screen image,,, sorry for disturbance,,,,

0 Kudos
Message 5 of 11
(6,923 Views)

I have attached the 8.6 version.

 

Best regards,

K


https://decibel.ni.com/content/blogs/kl3m3n



"Kudos: Users may give one another Kudos on the forums for posts that they found particularly helpful or insightful."
Message 6 of 11
(6,920 Views)

Thanks sir,,, appreciated,,, if possible can you write your e mail ,,, i think i need your evaluation....

0 Kudos
Message 7 of 11
(6,915 Views)

here i attached an example to show how i write the code,,, the information of position is signficant for my work,,, also my experience in c++ is not enough,,, if there is away just to write the image like nb [ j ] [ i ] it will be helpful for me,,,

thanks,,,

0 Kudos
Message 8 of 11
(6,907 Views)

@M.A.A.M wrote:

here i attached an example to show how i write the code,,, 


well, my recommendations are:

 

  1. Obtain latest versions LabVIEW and Vision. Especially Vision. Latest VDM is good optimized from performance point of view.

  2. Never call DLLs in UI Thread if not necessary.

  3. Never use Image to Array and Array to Image Vis. Just forgot about these VIs. Instead of conversion to array use IMAQ GetImagePixelPtr VI for obtain pointer to IMAQ Image. Here is very nice example, how to use this VI.

    In your case your function can be quick and dirty rewritten like this:

18-07-2013 23-11-50.png 

 

(take a note – I set border to zero, you should use LineWidth as described in the NI example above)

 

Also you can use pure IMAQ Vis for your calculations. They are pretty fast, because already based on DLL. This code functionally the same as code above:

 18-07-2013 23-13-45.png

Hope it helps.


Andrey.

 

Message 9 of 11
(6,890 Views)

thanks Andrey,, i use 2d array because after several image processing steps ,,, such like stretching i will obtain paricle ( see the attached image).... in my opinion is : i can track those edges if  i apply some tracking algorithm,,,, like this

 

if (nb[(j * col) + i]==0)
        {
            for (int j= 1; j< row-1; j++ )
                    {
                         for (int i = 1 ; i < col-1; i++ )
                                 {
                                    ip = (j*col)+i+1;
                                   

                                    im = (j*col)+i-1;
                               

                                    jp = (j*col)+i+col;
                               

                                     jm = (j*col)+i-col;

                                  }
                        }

                }

 

so i can search in side the image for the location of the edges....

 

so sir if there is some way to write the image like 2d array this will be helpful... usually i have something wrong when write the image like this : image [ j ] [ i ],,,,,,, i am keeping searching for a solution during the last two months,,,

but nothing changed... i have to keep trying and trying... 

 

 

( sir, iam student and this is not my option,,,, just i have to do it like 2d array Smiley Happy)

 

 

thanks for alllllll

0 Kudos
Message 10 of 11
(6,881 Views)