Jump to content

Sending IMAQ images via TCP/IP network


Recommended Posts

This is a very clever trick with some sample VI's on how to encode a live IMAQ image to a jpg string which allows you to send the image via TCP/IP.

I've done this and get about 11fps via intranet. This is from the NI web site - but it's so neat, that I am posting it here for posterity. What I also did for performance was to scale the image to 1/2 before encoding to make the image size even smaller.

Enjoy! Jack Hamilton

TRANSFERRING IMAGES WITH DATASOCKET (TCP/IP)

Problem: I am trying to send an image over a DataSocket connection in LabVIEW and the reading (client) VI is not able to display the received image. What can I do to correctly send the image?

Solution: One key consideration in sending an image over DataSocket is that it is not really an image being transferred but a pointer to the image. This is why the client program in the transfer is unable to display a received image. A good way of getting around this is to flatten the image using the Flatten to String.vi and send the bit string over the DataSocket Write. On the receiving end, the string must be unflattened with the Unflatten from String.vi before being displayed in the image indicator. In this way, all the data is sent across the DataSocket connection rather than just a pointer. See the attached DSReader and DSWriter examples which demonstrate this.

A related situation that may pose a limitation is trying to send grabbed images (continuous stream of images) over DataSocket. Sending the flattened data and trying to maintain a good fps (frames per second) rate can be difficult. Another approach is to apply some form of compression to the image. A lot of time can be cut off of the process by compressing the image into JPEG format, sending the data, and then uncompressing the JPEG into the image. Included below is a link that has an example program that demonstrates this. It utilizes a TCP/IP transfer method instead of the DataSocket, but the concept is the same.

Download File:post-37-1113494557.vi

Download File:post-37-1113494559.vi

Link to post
Share on other sites
A good way of getting around this is to flatten the image using the Flatten to String.vi and send the bit string over the DataSocket Write. On the receiving end, the string must be unflattened with the Unflatten from String.vi before being displayed in the image indicator.

4538[/snapback]

Be carfeul using FlattenToString with Datasocket. In the LV 6.02 version (and perhaps higher versions but I've never checked), DS recognises \00 as the terminator of the string (ie DS is a 'C' API and resolves 'C' style terminated strings). Flattened strings sometimes carry the \00 within them and the decode on the other end doesn't work because the entire string is never received by the DS Reader. You will need to bypass this with some smarts to make it a truly robust transfer.

cheers, Alex.

Link to post
Share on other sites
Be carfeul using FlattenToString with Datasocket. In the LV 6.02 version (and perhaps higher versions but I've never checked), DS recognises \00 as the terminator of the string (ie DS is a 'C' API and resolves 'C' style terminated strings). Flattened strings sometimes carry the \00 within them and the decode on the other end doesn't work because the entire string is never received by the DS Reader. You will need to bypass this with some smarts to make it a truly robust transfer.

cheers, Alex.

4562[/snapback]

Alex, I've actually tested and used this code in 6i so it does work. Good caution, I was sending B&W images which is only U8 data. Color images could be an issue.

Regards

Jack Hamilton

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.