LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert an image string to image

I used the "IMAQ Write String VI" to convert an image into a JPEG encoded string. How do I go about converting that string back to an image? 

 

I am trying to do this conversion in python but any advice (even to a VI that converts the string back to an image) would be greatly appreciated!

0 Kudos
Message 1 of 11
(3,565 Views)

Is there any particular advantage to using IMAQ Write String.vi over the primitive Flatten to String? The code below works just fine to go to/from a string. What are you trying to do exactly?

 

FireFist-Redhawk_0-1594757489979.png

 

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 2 of 11
(3,524 Views)

Yes I am using "IMAQ Write String.vi" because the primitive Flatten to String cannot be decode if the receiving machine does not have LabView. In my case, I am trying to send images from a computer that has LabView to one that does not have LabView. Therefore I can't use the Flatten to String option and instead was looking to use the "IMAQ Write String.vi" option.

0 Kudos
Message 3 of 11
(3,498 Views)

If the receiving PC doesn't have LabVIEW, how do you expect it to read an IMAQ string?

0 Kudos
Message 4 of 11
(3,480 Views)

This is something that I am grappling with at the moment and it is proving to not be trivial. My biggest problem is that carrying out jpeg decoding/encoding can be quite processor hungry (I am trying to convert 4 streams at 10Hz).

 

I have a system that is working that uses the following technique:

 

Converting a binary JPEG string in memory to IMAQ:

I use the code posted here which uses the Win32 dll's. It works well and I have had few problems so far.

https://forums.ni.com/t5/Machine-Vision/Convert-JPEG-image-in-memory-to-Imaq-Image/m-p/3786705/highl...

 

There is another method further up this thread which is noway near as efficient. It also can't handle corrupted frames very well, it doesn't give you an error it just silently crashes LabVIEW (I am using 2019f2). This was a big downside to me because I am streaming the JPEG data over UDP.

 

I did also play with writing the binary data to a file and then using the read jpeg function to read it back in as a IMAQ ref, this is also quite CPU hungry although I know there are tools which can partition a section of memory and treat it like a hard-drive which would probably speed it up...I didn't want to go down this road though.

 

Converting a IMAQ to binary JPEG in memory:

I have been using the flatten to string function to do this, if you use the options below this will produce a JPEG string. I have not noticed the IMAQ write to string function so am going to benchmark the two against one another today. I have benchmarked them and I am measuring no difference between the two functions. The write to string is a bit neater so go with that.

 

Edit: Upon looking over my code again I have remembered that you have to add the standard JPEG headers and footers for this to work, see attached VI.

 

 

0 Kudos
Message 5 of 11
(3,475 Views)

So the "Write JPEG String vi" outputs a JPEG encoded string. It should be possible to convert this string to a JPEG image, so there is no need for the receiving PC to have LabView because there is no IMAQ string.

0 Kudos
Message 6 of 11
(3,445 Views)

Thank you for this idea but I am trying to convert the JPEG string to JPEG, not IMAQ. The receiving end does not and will not (by design) have LabView installed on it, so converting to an IMAQ image is not very useful.

 

I really appreciate the response though!

0 Kudos
Message 7 of 11
(3,443 Views)

If all else fails, you can:

 

1. Save the image as a JPEG somewhere temporarily

2. Change the extension of the saved file from .jpg to .txt

3. Read the text contents of the .txt file

4. Delete the file and do whatever you want with the read data

 

To convert from string to JPEG, all you would need to do is make a .txt file whose contents are the read data from step 3, then change the extension to .jpg and open.

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 8 of 11
(3,435 Views)

I could do this but I don't want to use storage on my computer and I am trying to reduce lag and saving/reading each frame would definitely introduce lag. I am trying to send out the image frames without downloading them.

0 Kudos
Message 9 of 11
(3,430 Views)

Have you solved the problem? Now I also need to use c# parse the string of "IMAQ write string VI"

0 Kudos
Message 10 of 11
(2,547 Views)