07-14-2020 12:20 PM
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!
07-14-2020 03:11 PM
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?
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.
07-14-2020 06:34 PM
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.
07-14-2020 10:54 PM
If the receiving PC doesn't have LabVIEW, how do you expect it to read an IMAQ string?
07-15-2020 01:12 AM - edited 07-15-2020 01:29 AM
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.
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.
07-15-2020 12:49 PM
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.
07-15-2020 12:52 PM
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!
07-15-2020 01:10 PM
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.
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.
07-15-2020 01:18 PM
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.
03-15-2022 05:43 AM
Have you solved the problem? Now I also need to use c# parse the string of "IMAQ write string VI"