{"id":1504,"date":"2020-02-13T18:14:45","date_gmt":"2020-02-13T17:14:45","guid":{"rendered":"https:\/\/www.dpin.de\/nf\/?p=1504"},"modified":"2021-01-31T00:10:07","modified_gmt":"2021-01-30T23:10:07","slug":"thermal-camera-on-linux-flir-one-pro","status":"publish","type":"post","link":"https:\/\/www.dpin.de\/nf\/thermal-camera-on-linux-flir-one-pro\/","title":{"rendered":"Thermal Camera on Linux &#8211; FLIR ONE Pro"},"content":{"rendered":"<p>Recently I got myself a new toy, which is actually a very useful toy, a thermal camera! The one I got was used from eBay, a FLIR ONE Pro &#8222;for Android&#8220; with USB type-C connector, this is how it looks like:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1505\" src=\"https:\/\/www.dpin.de\/nf\/wp-content\/uploads\/sites\/2\/2020\/02\/flir-one-pro-160x120-1.jpg\" alt=\"\" width=\"640\" height=\"480\" srcset=\"https:\/\/www.dpin.de\/nf\/wp-content\/uploads\/sites\/2\/2020\/02\/flir-one-pro-160x120-1.jpg 640w, https:\/\/www.dpin.de\/nf\/wp-content\/uploads\/sites\/2\/2020\/02\/flir-one-pro-160x120-1-300x225.jpg 300w, https:\/\/www.dpin.de\/nf\/wp-content\/uploads\/sites\/2\/2020\/02\/flir-one-pro-160x120-1-624x468.jpg 624w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><\/p>\n<p>This is a pretty neat device as it attaches directly to the USB type&#8211;C port of a mobile phone (or other device). There is a second type-C connector on it which is only used for charging the internal battery. Why they included this is a bit beyond me, maybe they anticipated that not all Android phones would be able supply enough juice? The most important part though is the thermal image sensor. In the Pro version this has a resolution of 160&#215;120 pixel and a thermal range from -20C to +400C! Additionally there is a regular visible light camera included which can be used to overlay a visible picture onto the thermal (IR) one.<\/p>\n<h3>Debugging Electronic With Thermal<\/h3>\n<p>The main reason why I bought it was because I needed to debug some embedded electronics with it. Sound weird? Well yes, it may. Sometimes during development you end up in the situation that your circuit still consumes too much energy and you have no idea why, the only thing you do know that it shouldn&#8217;t. In a former project I spent weeks chasing down some 10mA and was not able to find it. What makes it so hard is that first you do not know if it is a software or hardware problem. And once you settle on the software side in many designs you quickly drown in possible options &#8211; so many pins, so many functions, so many components. And these all have to play nice together! You have to be sure what each and every component does at any given time or you may end up inadvertently driving two signals against each other or feeding power though a logic line to some component.<\/p>\n<p>Since electrical energy in circuits is turned into heat, a thermal camera is an awesome way to at least start to spot which of your components on a PCB gets warm. And if you are lucky, you know that it shouldn&#8217;t and can then look closer why this very thing still consumes power. In the before mentioned case we indeed found the sucker, which was a level shifter that got powered down in suspend but the host CPU was still driving a logic signal to &#8211; bam!<\/p>\n<p>My current target for analysis is the Purism Librem 5 phone and seeing which of the components draws most energy to then hunt them all down \ud83d\ude42<\/p>\n<h3>Getting It To Work<\/h3>\n<p>So the FLIR ONE Pro I got is intended for Android and with the FLIR Android app from the Google app store it works pretty much out of the box which is nice! The app has a bunch of nice features to play with and does it&#8217;s job. One nasty bit is though that FLIR always superimposes their company logo into the images takes, which is a bit annoying. But this is a USB device:<\/p>\n<pre>Bus 001 Device 009: ID 09cb:1996 FLIR Systems FLIR ONE Camera<\/pre>\n<p>Shouldn&#8217;t this also be able to work on Linux, on a regular laptop or so? First investigation shows, meh, not so easy, it is not a regular USB Video Class (UVC) device. Looking at the FLIR company website they offer a SDK for it, but only for Android and iOS, no hardware documentation and especially no Linux SDK. Pretty sad. Even more sad that they do not allow a free download of the SDK, you have to apply to get access, which Idid not do &#8211; this usually comes with a bunch of NDAs of sort, no thanks. But some more searching the net came up with the following Github project: <a href=\"https:\/\/github.com\/fnoop\/flirone-v4l2\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/github.com\/fnoop\/flirone-v4l2<\/a><\/p>\n<p>Wow, this is awesome! Though I was sceptical at first since it only mentions the FLIR ONE and I had the ONE PRO. To get this to work one also needs something I have not know before, a Video4Linux loopback device drivers, here: <a href=\"https:\/\/github.com\/umlaeute\/v4l2loopback\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/github.com\/umlaeute\/v4l2loopback<\/a> This kernel driver creates virtual V4L devices that a user space program can then feed video data into and other V4L applications will see this like any other regular V4L device, pretty cool!<\/p>\n<p>The driver compiles cleanly for Linux 5.4.x and 5.5.x (I am running 5.5.3 as of today). After compiling the driver and the program and insmodding the driver:<\/p>\n<pre>insmod .\/v4l2loopback.ko devices=3<\/pre>\n<p>and starting the application:<\/p>\n<pre>.\/flirone palettes\/Iron2.raw<\/pre>\n<p>the camera is active. Now you can start grabbing images from any application that can take V4L video input, for testing I used Guvcview and got this, holding my hand over the sensor:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1506\" src=\"https:\/\/www.dpin.de\/nf\/wp-content\/uploads\/sites\/2\/2020\/02\/my_photo-1.jpg\" alt=\"\" width=\"160\" height=\"128\" \/><\/p>\n<p>Isn&#8217;t that awesome!? Even with measurements! This is a great starting point for all kinds of application development. The low resolution of the shot here is the real physical resolution of the sensor &#8211; keep in mind, this is only 160&#215;120. The higher the resolution of a thermal sensor the exponentially higher its cost. The FLIR One Pro has an official price of $399 &#8211; ouch!<\/p>\n<p><strong>Update Jan. 2021:<\/strong> I took the flir-v4l code and hacked it into a GTK+ app which is more handy to use &#8211; you just start the app and don&#8217;t have to install the v4l loopback driver etc. The code is not finished yet, I am still struggling a bit with the Cairo drawing but it is working pretty nicely already, even the JPEG stream of the visual light camera gets decoded and can be overlayed to the IR image. If you want to give it a try, here is the code:<br \/>\n<a href=\"https:\/\/source.dpin.de\/nica\/flir-gtk\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/source.dpin.de\/nica\/flir-gtk<\/a><\/p>\n<p>That&#8217;s how it looks like right now:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1687 size-full\" src=\"https:\/\/www.dpin.de\/nf\/wp-content\/uploads\/sites\/2\/2020\/02\/shot.png\" alt=\"\" width=\"692\" height=\"681\" srcset=\"https:\/\/www.dpin.de\/nf\/wp-content\/uploads\/sites\/2\/2020\/02\/shot.png 692w, https:\/\/www.dpin.de\/nf\/wp-content\/uploads\/sites\/2\/2020\/02\/shot-300x295.png 300w, https:\/\/www.dpin.de\/nf\/wp-content\/uploads\/sites\/2\/2020\/02\/shot-624x614.png 624w, https:\/\/www.dpin.de\/nf\/wp-content\/uploads\/sites\/2\/2020\/02\/shot-60x60.png 60w\" sizes=\"auto, (max-width: 692px) 100vw, 692px\" \/><\/p>\n<p>The temperature is pretty obviously off, this seems to be a known problem of the reverse engineered Linux code, it has been discussed in the <a href=\"http:\/\/www.eevblog.com\/forum\/thermal-imaging\/question-about-flir-one-for-android\/\" target=\"_blank\" rel=\"noopener noreferrer\">EEV blog<\/a> too but seems without comclusion. What I am also still missing is code for changing camera settings (there are persistent setting in the camera?) and things like battery state etc&#8230; but well, it is already pretty cool as-is \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I got myself a new toy, which is actually a very useful toy, a thermal camera! The one I got was used from eBay, a FLIR ONE Pro &#8222;for Android&#8220; with USB type-C connector, this is how it looks like: This is a pretty neat device as it attaches directly to the USB type&#8211;C port of a mobile phone&#8230; <a href=\"https:\/\/www.dpin.de\/nf\/thermal-camera-on-linux-flir-one-pro\/\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":1506,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,2],"tags":[66],"class_list":["post-1504","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devices","category-geek-stuff","tag-thermal-imaging"],"_links":{"self":[{"href":"https:\/\/www.dpin.de\/nf\/wp-json\/wp\/v2\/posts\/1504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dpin.de\/nf\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dpin.de\/nf\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dpin.de\/nf\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dpin.de\/nf\/wp-json\/wp\/v2\/comments?post=1504"}],"version-history":[{"count":7,"href":"https:\/\/www.dpin.de\/nf\/wp-json\/wp\/v2\/posts\/1504\/revisions"}],"predecessor-version":[{"id":1690,"href":"https:\/\/www.dpin.de\/nf\/wp-json\/wp\/v2\/posts\/1504\/revisions\/1690"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.dpin.de\/nf\/wp-json\/wp\/v2\/media\/1506"}],"wp:attachment":[{"href":"https:\/\/www.dpin.de\/nf\/wp-json\/wp\/v2\/media?parent=1504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dpin.de\/nf\/wp-json\/wp\/v2\/categories?post=1504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dpin.de\/nf\/wp-json\/wp\/v2\/tags?post=1504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}