02-11-2009 09:18 AM
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.
02-11-2009 09:36 AM
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
02-11-2009 09:39 AM
02-11-2009 10:39 AM
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?
02-11-2009 12:02 PM - edited 02-11-2009 12:03 PM
Hi,
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.
Andrey.
PS
Otherwise (personally) I will never use such hack in commercial application ;).
02-11-2009 01:18 PM
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.
Bruce
02-11-2009 01:27 PM
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.
04-04-2010 08:03 PM
I posted an idea request for a function to convert strings back to images. Please vote for it at:
Thanks,
Bruce
04-27-2018 01:28 AM
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.
05-14-2018 05:50 AM