Giter Club home page Giter Club logo

ircam-viewer's Introduction

Linux Infrared Camera Viewer

A lightweight GUI for viewing and recording output from USB infrared cameras.

Features include:

  • FFV1 lossless 16-bit video recording
  • Native support for remote viewing over the network
  • Full manual control of view dynamic range in software
  • Runs both under X and as a standalone program
  • Font caching using SDL_FontCache
  • Precomputed gamma correction lookup tables
  • Fixed point arithmetic

I hacked this together to make better use of the TOPDON TC001, a (relatively) cheap 256x192 25hz USB infrared camera designed to be plugged into a cell phone.

The exact hardware: https://www.amazon.com/dp/B0C23Z42KX

My goal was to write something fast enough to render the video in real time with 1080p upscaling on a Raspberry Pi Zero W (the older single core ARMv6 without hardware division).

It works!

My initial implementation relied on the BCM2835 hardware floating point support, and pegged the CPU at 10fps on the Zero. Converting that floating point arithmetic to fixed point and/or lookup tables improved it to 20fps.

Using SDL_FontCache to render the text finally got it to 25fps, but it was so close to the edge that simply pinging the Pi from my laptop would make it drop frames!

The final optimization was to refactor the scaling math: each frame requires a division for each pixel (code), but the divisor is the same across the entire frame. So what were then software divisions became hardware multiplications at the cost of one extra software division (to compute the multiplicative inverse), an obviously economical proposition with 49152 pixels in each frame. With that final improvement, the formerly overloaded Pi Zero W is now 50% idle.

I additionally implemented a 256KB lookup table of all 65536 necessary 32-bit multiplicative inverses, but it showed no measurable advantage on the Pi in testing, so I removed it.

Building

$ sudo apt install libsdl2-dev libsdl2-ttf-dev libavcodec-dev libavformat-dev

$ make -j -s

Currently, only two specific camera models are supported: TOPDON TC001 and RX-450, but more will be added in the future.

Viewing

$ ./ircam -d /dev/video4

In the upper left, you'll find the minimum, point measurement, and maximum temperatures. The second row shows the current view dynamic range limits, or AUTO in automatic mode. The third row shows gamma correction and contouring settings.

The point measurement is the temperature at the center of the cross. The temperatures are displayed at the true underlying granularity. The viewer is controlled entirely using the keyboard, the mouse doesn't do anything (yet). The emissivity is always assumed to be 1.0.

You can view the help text at any time by holding the [H] key:

The [C] key toggles between grayscale and the Turbo colormap. [I] inverts the sense of the display, and [G] toggles through gamma correction options.

The [Y] key enables "contouring": this repeats the colormap N times through the current view dynamic range instead of just once, allowing you to visualize more than eight bits on your 8-bit display.

Dynamic range (or exposure) starts in AUTO mode. Pressing [E] at any time will revert to AUTO. Pressing [D] enters manual mode, pinning the min/max of the view dynamic range at their current values.

In manual mode, [Q] and [A] raise and lower the minimum view dynamic range. The [W] and [S] keys do the same for the maximum view dynamic range. The [Z] and [X] keys pin the ranges at their absolute minimum/maximum.

The [T] key toggles the onscreen text between white, black, and off (it is never recorded), and the [F] key will toggle units between Celsius and Fahrenheit.

The arrow keys move the cross, which is where the point temperature is from.

Recording

The [R] key begins raw 16-bit recording. Each recording goes to a new file named for the epoch at the time it begins. Pressing [R] a second time ends the current recording.

The generated Matroska files should be compatible with anything that understands FFV1 video compression, but due to how compressed the useful dynamic range of the image becomes, they look incorrect at first glance:

The [V] key begins RGB recording, which exports the actual view you see in the window at the time.

The expectation is that you will use 16-bit recording to capture a scene, then use playback mode to adjust the dynamic range, finally enabling RGB recording to make a finished product. But you can record RGB directly from a live camera.

The "-n" command line flag will record 16-bit video without rendering output, so you can use a headless machine to drive the camera.

Playback

$ ./ircam -p your-recording.mkv

All the viewing hotkeys described above work during playback, including the dynamic range settings. This is possible because the full 16-bit value is recorded for each pixel in each frame.

During playback, the spacebar pauses the video. Pause timings are included in RGB recorded video. RGB recording will always end when the video loops. 16-bit recording is not supported in playback mode.

Remote Viewing

You can plug your IR camera into a headless system, and connect and view the output with all the usual features from another.

On the system with the camera attached, run:

$ ./ircam -l

Then, connect to its IP address from the other system:

$ ./ircam -c 1.2.3.4

...replacing '1.2.3.4' with the appropriate address on your network.

Any recorded video is stored locally as usual. It is possible to combine both -l and -n, but the recording will not begin until a remote client connects.

Converting Video

$ ffmpeg -i 1-rgb.mkv -f mp4 -c:v h264 -crf 17 highquality.mp4

$ ffmpeg -i 1-rgb.mkv -f mp4 -c:v h264 -preset veryfast mobile.mp4

ircam-viewer's People

Contributors

jcalvinowens avatar roboschmied avatar

Stargazers

 avatar Caspar avatar Mike Kasprzak avatar  avatar Emmanuel Guillot avatar Emil Burzo avatar Roman avatar

Watchers

 avatar  avatar  avatar

Forkers

roboschmied

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.