Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

IMAQ GetImagePixelPtr Unmap Pixel Pointer - do I really need this?

Hi!
 
What exactly does IMAQ GetImagePixelPtr with Unmap Pixel Pointer function? The Help says "Frees the pointer and related information previously obtained using Map Pixel Pointer." OK, Map Pixel Pointer will return pointer to pixel (0,0). But after Unmap this pointer still valid... Why we needed Unmap Pixel Pointer?
 
In general there are two questions:
1. What may happened theoretically if I will forgot Unmap Pixel Pointer after Map Pixel Pointer?
2. Do I need to call Map/Unmap pixel pointer if I working with images directly in my DLLs?
 
thank you in advance,
 
Andrey.
 
Message 1 of 10
(10,936 Views)
Andrey -

Good question!  The answer is that as of the current version of Vision, Unmap Pixel Pointer doesn't do anything significant.  However, that is an implementation detail, and it is possible that it will be necessary to call it after Map Pixel Pointer in future versions of Vision, so I strongly encourage you to call it anyway to avoid problems in the future.  Is there a particular reason that calling Unmap Pixel Pointer is undesirable, or were you just curious?

Greg Stoll
Vision R&D
National Instruments
Greg Stoll
LabVIEW R&D
0 Kudos
Message 2 of 10
(10,928 Views)

Hi, Greg,

Thank you for the answer. Let me explain my question.

When I need to make some calculation inside of the DLL, then recommended way looks like this (got it from NI Help):

According C code should be:

I don't like such method, because for each image I must transfer to the DLL: pointer, width, height, linewidth, etc.
I prefer more simple way:

Now I will obtain all image parameters inside of my DLL code, and I have only single argument instead of multiple:

But now I'm not sure - probably I must "isolate" direct usage of the pointer (imageStart member of the ImageInfo) with Map/Unmap calls? Probably MapPixelPointer will "lock" pointer and will prevent relocation of the image in the memory in LabVIEW during LLB call, or something like this... Or given code is safe? This is why I'm asking about detailed explanation of UnMap function.

with best regards,

Andrey.

Message 3 of 10
(10,921 Views)
Andrey -

Ah, I see what you're doing.  While this isn't officially supported, it seems very unlikely that doing things like this would stop working in the future, and you don't need the MapPixelPointer and UnmapPixelPointer calls in the C code.

Additionally (just to be clear), in the C code you can treat the LVImage as a normal Image* and call imaqSetImageSize(), imaqFillImage() etc. on it without the need for an extra testImage.

Good luck in your application!

Greg Stoll
Vision R&D
National Instruments
Greg Stoll
LabVIEW R&D
Message 4 of 10
(10,919 Views)

Greg, thank you again,


Now I understand a bit more.
Sure, I can use LVImage as normal image in all IMAQ functions inside of my DLL. That was only modified NI example for better understanding. Usually I using native IMAQ functions in my DLLs relative rarely (because LabVIEW much better for such work), but when I needed high performance special image processing (which cannot be done with Vision Toolkit), then I writing this code in C, because in some cases the native LabVIEW constructions are too slow for me. The same things with other libraries - such Intel IPP, framegrabbers API, etc - easiest way is using the DLL wrapper where IMAQ Image will be transferred to third party library and back.
Fully understand, that direct transfer of the IMAQ Image is not supported by NI, but this is really most convinient way (at least for me).

with best regards,

Andrey.

PS
I still can't figure out how to avoid DataType conversion functions before and after my DLL:

 but this is probably not for this discussion...

0 Kudos
Message 5 of 10
(10,914 Views)

Dear Andrey Dm

 

I wan to use Getimagepixelptr.vi.

But I do't make DLL(Copy_c_image_tolabview_image).

I hope to received it.

Please send.

 

Bongchan Park(loglab@naver.com)

0 Kudos
Message 6 of 10
(10,486 Views)

Hi,

 

IMAQ GetImagePixelPtr.vi delivered with IMAQ Vision Toolkit and located in the palette Vision Utilities->Image Management->External Library Support->IMAQ GetImagePixelPtr.vi

 

Andrey.

0 Kudos
Message 7 of 10
(10,478 Views)

Dear

 

I need DLL(copy_c_image_tolabview_image).

I want to receive DLL(copy_c_image_tolabview_image) file

Sincerely yours,

 

Bongchan Park(loglab@naver.com)

0 Kudos
Message 8 of 10
(10,467 Views)
I also want to transfer a lv image pointer to my DLL , can you give me some tips about how make it. may be the imageto array is a little slow for my use . thanks
0 Kudos
Message 9 of 10
(9,271 Views)

Could someone clarify the operation of the map and unmap pixel pointer sequence here.

As I understand it we set aside memory for the image in Labview, then we take a pointer to this Labview memory and after mapping it the C world using map pointer, we then pass this pointer to DLL. The DLL in turn then just does a memcpy from the C world to the Labview pointer world. However, at the end of the day, there is still a memcpy happening under the hood so to speak which is fairly inefficient I would have thought. However, I may have mi-understood what is happening here.

 

Is there any way of returning a pointer from the C world to Labview world without having to do a memcpy along the way?

 

Thanks for any replies,

Dave

0 Kudos
Message 10 of 10
(8,183 Views)