Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Decoding jpeg string

I aquire a picture in labView trough an activex wrapper for my cameras sdk methods. I download the picture to a buffer of U8s, convert it to a string and save it to a jpeg file. Then I open the file again to convert it to the IMAQ image type for further processing.

My question is: Is there anyway to avoid saving the data to a file first, so that the application can speed up a bit? In other words is it possible to convert the jpeg string/array directly to an IMAQ Image?

I tried to use the IMAQ JPEG Decode VI which followed in an example in this site, but it required "IMAQ Image.ctl" which I haven't found.

Is it possible to use this VI for this purpose?
Where can I locate "IMAQ Image.ctl"?

Torodd
0 Kudos
Message 1 of 17
(7,388 Views)
This is precisely what the IMAQ JPEG Decode VI does. It converts a JPEG encoded string to an IMAQ image without saving it to a file. The string is the equivalent of the contents of the file.

The IMAQ Image control should be on your IMAQ palette for the front panel. If you don't have IMAQ Vision, that might be the problem. I am not sure if IMAQ Vision is required to use the JPEG/string conversions. You should be able to disconnect the control from its type definition to get the example to work.

FYI, the direct conversion from string to IMAQ image is much, much faster.

Bruce
Bruce Ammons
Ammons Engineering
0 Kudos
Message 2 of 17
(7,389 Views)
Thanks for the quick response.

I got the VI runnable, but now it gives me an exception when I run it. What can be the error now?

I pass in an initialized array of U8 (values 0) with the size of the picture (aquired from the camera and passed in as dimension) to the getImage method. I get out the variant with the data, pass it to variant to flattened string, remove 8 bytes (hex: 0008 BE65 FFD8 FFE1) in the beginning (had to do this to make labview recognise the jpeg file - why are these 8 bytes added by variant to flattened data?, the string now starts: hex: FFD8 FFE1 3845 4578 6966 0000 4949 2A00 0800 ("ÿØÿá8EExif II*...")), and pass this to decode Jpeg.vi together with a new IMAQ image (tried different types). When I run it I get an exception and the exec
ution is stopped at node 0x530. I really would like to make this work if it speeds up my application. Any idea what might be wrong?

By the way Ive got IMAQ Vision installed.

Torodd
0 Kudos
Message 3 of 17
(7,391 Views)
By the way that was 16 bytes not 8 that I removed, but I guess you figured that..
0 Kudos
Message 4 of 17
(7,392 Views)
Not really sure what might be wrong.

One idea is to save the image to disk the way you have been doing, then read it in as a string to compare it with your flattened variant. There might be other differences that you need to account for.

You might want to convert your variant back to a U8 array, then convert it to a string. This might produce a different result.

By the way, I only count 4 bytes, unless the same sequence (FFD8 FFE1) is repeated. Each two digits is a byte.

Bruce
Bruce Ammons
Ammons Engineering
0 Kudos
Message 5 of 17
(7,393 Views)
Actually I made it work, deleted a version of the library and tried another one and now it works, only that the colours in the picture are different from the reality. I take a picture in blue light and it displays on the screen as if it where red. A buddy of me here suggested that it had something to do with the way windows code colours and that it might be possible to rearrange the pixel values if I made a pixel map out of the image, but it might be a lot of work. Do you know the phenomenon? Or is this something else that is wrong, why does it happen?

The 4 bytes, which are messing with my head, seems to be ok to remove.

Thanks again.

Torodd
0 Kudos
Message 6 of 17
(7,394 Views)
Hi, interesting discussion. I have one more question: Where can I locate the 'IMAQ JPEG Decode' ? I have Vision 6.1 and LabVIEW 6.1 installed.
Thanks, Oliver
0 Kudos
Message 7 of 17
(7,395 Views)
Search for the example on the Developer Zone. It is actually part of a demo for streaming images to a remote location, but you can pull out the routines that convert from image to JPEG string and back.

Bruce
Bruce Ammons
Ammons Engineering
0 Kudos
Message 8 of 17
(7,396 Views)
I have the same problem - I'm taking images from a Kodak SDK and the blue and red color channels are reversed. I created a quick VI to solve the problem using the ExtractColorPlanes.vi and ReplaceColorPlanes.vi from the IMAQ tools. Basically, you split the image into its 3 color planes using the first VI and then reconstruct it by switching the blue and red inputs when you replace the color planes.
0 Kudos
Message 9 of 17
(7,396 Views)
I'm trying to find the mentioned example. This thread is some days old and it seems that with changes in the examples and tutorial part of the site this one has been lost. It seems that this is the counterpart to the IMAQ Write String VI in the Vision Utilities Files Palette.
I someone able to pint me into the right direction?
Waldemar

Using 7.1.1, 8.5.1, 8.6.1, 2009 on XP and RT
Don't forget to give Kudos to good answers and/or questions
0 Kudos
Message 10 of 17
(6,643 Views)