gtatters / Thermimage

R Package for working with radiometric thermal image files and data
GNU General Public License v3.0
164 stars 41 forks source link

frameLocates() error #2

Closed rimamrahal closed 5 years ago

rimamrahal commented 5 years ago

To get acquainted with Thermimage, I tried to reproduce the README file.

Running the code with the SampleFLIR.seq file provided in the description works without error.

library(Thermimage)
exiftoolpath <- "installed"
perlpath <- "installed"

v <- "SampleFLIR.seq"

camvals <- flirsettings(imagefile = v)
w <- camvals$Info$RawThermalImageWidth
h <- camvals$Info$RawThermalImageHeight

fl <- frameLocates(v,w,h)

However, when I run the cose using a video recording from our FLIR thermal imaging camera stored as a .seq file like this:

library(Thermimage)
exiftoolpath <- "installed"
perlpath <- "installed"

v <- "Rec-000099.seq"

camvals <- flirsettings(imagefile = v)
w <- camvals$Info$RawThermalImageWidth
h <- camvals$Info$RawThermalImageHeight

fl <- frameLocates(v,w,h)

frameLocates() returns an error:

Error in if (wh.locate[1] < header.l & no.unique.locates == 2) { : 
  missing value where TRUE/FALSE needed

Any idea what might be going wrong?

gtatters commented 5 years ago

Hi Rima

Thank you for posting this. I can confirm that I get the same error.

I worried I might find an issue like this one day! The .seq file type contains meta tags that Thermimage does not fully understand. When the package was put together, I only had access to SEQ files that were generated using Thermacam Researcher Pro.

The frameLocates() function is unfortunately a bit of a legacy function from the time when I first started the package (I was so naive), so troubleshooting this may force me to re-visit some old code. Thus, I'll leave this issue open until/if I get this fixed and will provide updates.

For this reason, I did add conversion functions that would allow you to convert the SEQ file using Exiftool, ImageMagick and FFMPEG, all called from convertFLIRVid.

Can you see if using the convertflirVID function will work on your system:

convertflirVID(v, exiftoolpath="installed", perlpath="installed",
               fr=30, res.in="640x480", res.out="640x480", outputcompresstype="png", 
               outputfilenameroot=NULL, outputfiletype="avi", outputfolder="output", verbose=FALSE)

will generate an avi grayscale file you could analyse without the aggravation.

Or use this to generate a folder of pngs:

convertflirVID(v, exiftoolpath="installed", perlpath="installed",
               fr=30, res.in="640x480", res.out="640x480", outputcompresstype="png", 
               outputfilenameroot=NULL, outputfiletype="png", outputfolder="output", verbose=FALSE)

Regards Glenn

gtatters commented 5 years ago

Update: I found where the error was in frameLocates. Ironically, I had a calculation in place to check for a particular type of error that I've never encountered. Funny thing, the error check was faulty. So, I've tried to fix it. I uploaded a minor update (v. 3.1.4) and it ran the frameLocates() without error on my system.

v <- "Rec-000099.seq"
camvals <- flirsettings(imagefile = v)
w <- camvals$Info$RawThermalImageWidth
h <- camvals$Info$RawThermalImageHeight
fl <- frameLocates(v,w,h)
frames<-getFrames(v, fl$f.start)
alldata<-unlist(lapply(fl$f.start, getFrames, vidfile=v, w=w, h=h))
alldata<-matrix(alldata, nrow=w*h, byrow=FALSE)
plotTherm(alldata[,1], templookup=NULL, w=w, h=h,  minrangeset=min(alldata[,2]),
          maxrangeset=max(alldata[,2]), trans="mirror.matrix")

rplot

However, the memory use required to load SEQ files into working memory makes the frameLocates() and getFrames() functions unfeasible to use on anything except small SEQ files (<100 Mb). This is why I added the convertflirVID and convertflirJPG functions which would also allow the user to convert files for use outside of R or by re-importing into R as png, tiff, or avi files.

Note: the getTimes() function relies on knowing where the frame time stamps are located in the SEQ files. Your camera file seems to be different than the one I used to extract time stamps, so I would have to examine why that is the case.

v 3.1.4 will be on github. I won't update CRAN until further tests.

rimamrahal commented 5 years ago

Works perfectly, thank you!