LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How is imaqSubtract so fast?

I'm trying to write my own image subtraction script and am only getting half of the framerate that I do with imaqSubtract function and I was wondering if NI was doing something tricky to get the higher frame rate. 

 

I am using imgSessionCopyBuffer to copy the image data from the ring I set up to an array already stored in memory.  Then I subtract another array that already has an image stored in it  and display the differenced image.

 

I can get 30 Hz using imaqSubtract but can only get 15 Hz using my function.

The camera's bit depth is 12 bits and the array the images are stored in are shorts (16 bit).

I'm using Labwindows/CVI, the development machine has VDM but I need a subtraction function for a machine that doesn't have the VDM license due to a really tight budget.

 

Thanks!

0 Kudos
Message 1 of 4
(2,865 Views)

I ran into similar things creating my own image manipulation functions.  The built-in CVI compiler is not particularly good about optimizing code.  In order to get the speed I wanted I had to use another compiler.  You can make CVI use a different compiler in the build options.  Later versions of CVI ship with a copy of the free Clang compiler, and it's fairly straightforward to use it if you search this forum.  Another option is to build the functions into a DLL outside of CVI and then call the functions in that DLL from your CVI program.  That's what I ended up doing using gcc with the -O3 option.  My guess is that the IMAQ libraries are compiled by NI using Microsoft's compiler, but I'm not sure about that.

Message 2 of 4
(2,856 Views)

Do you use MMX instructions in your code?  If not, there is almost no chance to produce code with the same speed.

The MMX instruction set was introduced by intel in the late 1990ies.  The CPUs had the term "MMX" in their names at that time (e.g. "Pentium MMX").  MMX instructions allow for operating on 8 8bit values or 4 16bit values (ans further stuff) with one(!) instruction.  This is hard to beat by a for loop that iterates on each pixel value individually ...

Message 3 of 4
(2,834 Views)

Whether or not it uses MMX instructions would be up to the compiler, especially since CVI does not support inline asm.  With gcc I specify that the target machine is at least a Pentium 4 so I assume that gcc will use MMX (and possibly SSE, SSE2, etc.) where appropiate.  CVI's compiler doesn't have a similar option so I don't know if it will use MMX instructions or not.  Minimum requirements for CVI is a 1 Ghz processor which we can assume has MMX.  Maybe an NI engineer can comment.

0 Kudos
Message 4 of 4
(2,813 Views)