Language: Swift 3
What I am using: Hardware: An IPhone 6 and FLIR One thermal camera Software: Xcode 8.1, Locked down FLIROne SDK (written and documented for obj-c and has little documentation at all)
What I am trying to do: Get the temperature of the center pixel from the returned camera stream
The problem: I have everything in the app I am building setup and working as expected not including getting this thermal data. I have been able to get temperature from the returned stream from the camera, however I can only get it for the 0,0 (top left) pixel. I have crosshairs in the center of the image view that the stream feeds into and I would like to get the pixel at this center point (the exact center of the image). I have been working on this for two days and I can't seem to figure out how to do this. The SDK does not allow you to specify which pixel to read from and from what I have read on online, you have to loop through each pixel and stop at the center one.
The below code will get the temperature from pixel 0,0 and display it correctly. I want to get temperature to read center pixel instead. temperature MUST be UInt16 to provide correct Kelvin readout (from what I understand at least), but I receive the radiometric data from Data! as UInt8. NOTE: NSData! does not work with these delegates. Attempting to use it (even in swift 2.3) causes the delegate to never fire. I have to use Data! for it to even run the delegate. I found it very odd that I couldn't use swift 2.3 because it only has NSData. If this is because I screwed something up please let me know.
func flirOneSDKDelegateManager(_ delegateManager: FLIROneSDKDelegateManager!, didReceiveRadiometricData radiometricData: Data!, imageSize size: CGSize) {
let byteArray = radiometricData?.withUnsafeBytes{
[UInt8](UnsafeBufferPointer(start: $0, count: (radiometricData?.count)!))
}
let temperature = UnsafePointer(byteArray!).withMemoryRebound(to: UInt16.self, capacity: 1){
$0.pointee
}
debugPrint(temperature)
DispatchQueue.main.async{
self.tempLabel.text = NSString(format: "%.1f",self.convertToFarenheit(kelvin: temperature)) as String
}
}
I am new to Swift so I am not sure if this is the best way to do this so if you have a better way please advise me on it.
Current solution: Gets the center pixel, but not dynamically (which is what I want)
let byteArray = radiometricData?.withUnsafeBytes{
[UInt8](UnsafeBufferPointer(start: $0, count: (radiometricData?.count)!))
}
let bytes:[UInt8] = [(byteArray?[74170])!,(byteArray?[74171])!]
let temperature = UnsafePointer(bytes).withMemoryRebound(to: UInt16.self, capacity: 1){
$0.pointee
}