I need to convert and display a JPEG image in LabVIEW l that I continously capture from Canon 1D Mark III camera using the Canon SDK. We have a dll wrapper for the SDK that downloads the images into memory so we have a pointer to the jpeg image stream and its size. Now we just need to convert the JPEG image to the IMAQ image type.
The problem we're running into is that it appears the JPEG - IMAQ conversion functions are buried inside the IMAQ ReadFile vi. Unless I'm missing something simple is saving the JPEG file and reading it back with IMAQ readfile the only way to easily get a JPEG image into an IMAQ image?
I also downloaded some code from the forums called IMAQ JPEG decode that converts a binary JPEG stream, but it has a couple problems including a big memory leak and swapping red and blue color planes.
The JPEG image is 1024x680 32bit RGB.
Unfortunately, that is the only way to do it - write a file and read it back. The string decoder works well for grayscale images, but not color, as you discovered.
I have been bugging the Vision R&D team to add this simple functionality, but they don't see the need. Perhaps if you submit a feature request that would help.
Bruce thanks for the reply.
It seems like the R&D team has done this before in the IMAQ_JPG.dll that is called by IMAQ Jpeg Decode vi's. Does anyone know who wrote that dll?
Why do not use suggestion from Bruce? Quick and dirty test shows that It works in general:
The only problem that I haven't found where in header the length of the jpeg part was stored. So, I create "dummy" jpeg which is guaranteed bigger than original, and then perform jpeg part replacement and pad with zeroes after that (otherwise you will get error from Unflatten). In attachment two examples - one for 8 bit and another one for rgb image both are OK for play.
Otherwise (personally) I will never use such hack in commercial application .
Andrey - impressive work! I had the idea, but I wasn't sure how to implement it. Your method appears to work well.
Somebody in NI R&D wrote those JPEG decode routines many years ago. I don't think he is in R&D anymore. I chatted with him about them long ago, but I can't recall his name at the moment. They were actually designed so that images could be easily transferred from a remote RT target back to a host PC, but they work great for many other uses. I like to be able to pack a large number of images into a single file, which reads and writes much faster than individual images.
Andrey that is impressive. I will look at incorporating in my code. It just seems like for the $$$ spent for the toolkit it should be a built in function.
Bruce - I submitted a feature request.
I posted an idea request for a function to convert strings back to images. Please vote for it at:
I've had a similar task of converting JPEG image stream into a common 32-bit RGB array, that could be passed to IMAQ VIs. As I'm working in 64-bit version of LabVIEW, I ended at Windows Imaging Component (WIC) and its proxy functions (thanks to this thread). So, I have rewritten that C code in pure LabVIEW with the help of CLFN blocks (ole32, windowscodecs and shlwapi calls). Here's how to use it:
Works fine in both 32- and 64-bit LabVIEW and doesn't need any non-standard external libraries or .NET assemblies. Moreover WIC is able to read not only JPEG, but any other widespread formats, such as PNG, BMP etc.
Try it and tell me, how it goes for you.