GPU Software for Machine Vision Cameras

Author: Fyodor Serzhenko

Cameras for machine vision, industrial and scientific applications are quite widespread nowadays. These solutions utilize USB3, GigE, 10GigE, 25GigE, CameraLink, Coax, Thunderbolt, PCI-Express interfaces to send data from camera to PC. Usually cameras transfer RAW data and we need to implement quite complicated image processing pipeline to convert RAW to RGB in realtime. This is computationally heavy task, especially for high speed and high data rate cameras.

gpu software machine vision genicam

Realtime image processing for machine vision cameras could be done on Intel/AMD CPUs, but that solution is difficult to speedup further, which is the case for multicamera systems. To overcome such a bottleneck, one could implement simplified algorithms on CPU to be on time, but it can't be a good solution. Most of high quality algorithms are slow even at multicore CPUs. The slowest algorithms for CPU are demosaicing, denoising, color grading, undistortion, resize, rotation to an arbitrary angle, compression, etc.

To solve that task we utilize Fastvideo SDK which is working on NVIDIA GPU. With that SDK we can implement a software solution where full image processing pipeline is done on graphics processing unit (GPU). In that case the software architecture is much more simple, because processing part is fully done on GPU and it doesn't interfere any more with CPU-based features.

Fast CinemaDNG Processor software

As a good example of high performance and high quality raw image processing we could recommend Fast CinemaDNG Processor software for Windows, where all computations are done on NVIDIA GPU and its core is based on Fastvideo SDK engine. With that software we can get high quality image processing according to digital cinema workflow. One should note that Fast CinemaDNG Processor is offering image quality which is comparable to the results of raw processing at Raw Therapee, Adobe Camera Raw and Lightroom Photo Editor software, but significantly faster. Total speedup could be estimated as 10-20 times or even more.

To check GPU-based performance for your machine vision camera on Fast CinemaDNG Processor software, we can convert RAW images to DNG format with our open source PGM2DNG converter, which could be downloaded from Github. After such a convertion the software will be able to work both with digital cinema cameras like Blackmagic Design and with machine vision / industrial cameras.

machine vision camera sdk gpu

GPU Camera Sample Project

Here we will show how to implement a software with GPU image processing pipeline for any machine vision camera. To accomplish the task we need the following:

  • Camera SDK (XIMEA, Basler, JAI, Imperx, Baumer, Flir, etc.) for Windows
  • Optional GenICam package with camera vendor GenTL producer (.cti)
  • Fastvideo SDK (demo) ver.0.15.0.0 for Windows
  • NVIDIA CUDA-10.1 for Windows and the latest NVIDIA driver
  • Qt ver.5.13.1 for Windows
  • Compiler MSVC 2017

Source codes and links to supplementary libraries for GPU Camera Sample project you can find on Github.

As a starting point we've implemented the software to capture raw images from XIMEA cameras. We have utilized sample application from XIMEA SDK and we have incorporated that code into our software. In the software we set default camera parameters to focus on GPU-based image processing, though you can add any GUI to control camera parameters as well.

Simple image processing pipeline on GPU for machine vision applications

  • Raw image capture (8-bit, 12-bit packed/unpacked, 16-bit, monochrome or bayer)
  • Import to GPU
  • Raw data convertion and unpacking
  • Linearization curve
  • Bad pixel removal
  • Dark frame subtraction
  • Flat-field correction
  • White Balance
  • Exposure correction (brightness control)
  • Debayer with HQLI (5×5 window), DFPD (11×11), MG (23×23) algorithms
  • Wavelet-based denoising
  • Gamma
  • JPEG compression
  • Output to monitor with minimum latency
  • Export from GPU to CPU memory
  • Storage of compressed data to SSD or streaming via FFmpeg RTSP

It's possible to modify that image processing pipeline according to your needs, as soon as source codes are available. There are much more image processing options in the Fastvideo SDK to implement at such a software for GPU-based image processing in camera applications.

The software has the following architecture

  • Thread for GUI and visualization (app main thread)
  • Thread for image acquisition from a camera
  • Thread to control CUDA-based image processing
  • Thread for OpenGL rendering
  • Thread for async data writing to SSD or streaming

With that software one could also build a multi-camera solution for any machine vision or industrial cameras with image processing on NVIDIA GPU. In the simplest case, user can run several processes (one per camera) at the same time to accomplish the task. In more sofisticated approach it would be better to create one image loader which will collect frames from different cameras for further processing on GPU.

There is also an opportunity to utilize different compression options on GPU at the end of the pipeline. We can utilize JPEG (Motion JPEG), JPEG2000 (MJ2K), H.264 and H.265 encoders on GPU. Please note that H.264 and H.265 are implemented via hardware-based NVIDIA NVENC encoder and that video encoding could be done in parallel with CUDA code.

From the benchmarks on NVIDIA GeForce RTX 2080ti we can see that GPU-based raw image processing is very fast and it could offer very high quality at the same time. The total performance could reach 4 GPix/s. The performance strongly depends on complexity of the pipeline. Multiple GPU solutions could significanly improve the performance.

The software could also work with raw images in PGM format (bayer or grayscale) which are stored on external SSD. This is a good method for software evaluation and testing without a camera. User can download the source codes from Github or ready binaries for Windows from GPU Camera Sample project page.

We've done some tests with raw frames in PGM format from Gpixel GMAX 3265 image sensor. That image sensor has resolution 9433 × 7000. For 8-bit mode we've got total processing time on GPU around 12 ms which is more than 4 GPix/s. The pipeline includes data copy from host to device, dark frame, FFC, linearization, BPC, white balance, debayer HQLI, gamma sRGB, 16/8-bit transform, JPEG compression (subsampling 4:2:0, quality 90), viewport texture copy, monitor output at 30 fps. The same solution for 12-bit raw image could give us 14 ms processing time.

Here we can see absolutely incredible performance for JPEG encoding on NVIDIA GPU: 65 MPix color image (24-bit) could be compressed within 3.3 ms on NVIDIA GeForce RTX 2080ti.

We recommend to utilize that software as a testing tool to evaluate image quality and performance. User can also test different NVIDIA GPUs to choose the best hardware in terms of price, quality and performance for a particular task.

Custom software design

GPU Camera Sample project is just a simple application which shows how user can quickly integrate Fastvideo SDK into real project with machine vision, industrial and scientific cameras. We can create custom solutions with specified image processing pipeline on NVIDIA GPU (mobile, laptop, desktop, server), which are much more complicated in comparison with that project. We can also build custom GPU-based software to handle multicamera systems for machine vision or industrial applications.

Roadmap for GPU Camera Sample project

  • GPU pipeline for monochrome cameras - done
  • GenICam Standard support - done
  • Support for XIMEA, Basler, JAI and Daheng Imaging cameras (USB3) - done
  • Video streaming option (MJPEG via RTSP) - done
  • Linux version - done
  • Software for NVIDIA Jetson Nano, TX2, AGX Xavier - done
  • Glass-to-Glass (G2G) test - done
  • Support for Imperx cameras - in progress
  • GenICam option for Fast CinemaDNG Processor
  • H.264/H.265 encoders on GPU
  • CUDA JPEG2000 encoder
  • Curves and Levels via 1D LUT
  • Color correction with 3x3 matrix
  • Transforms to Rec.601 (SD), Rec.709 (HD), Rec.2020 (4K)
  • 3D LUT for HSV and RGB with cube size 17, 33, 65, 96, 256, etc.
  • Interoperability with external FFmpeg and GStreamer

References

Other blog posts on GPU software for camera applications

Contact Form

This form collects your name and email. Check out our Privacy Policy on how we protect and manage your personal data.