1. Preliminary preparation
1. Software to be downloaded
1.1 visual studio 2017
Versions from other years are also available
1.2 Pycharm 2022
Versions from other years are also available
1.3 DJI Thermal Analysis Tool 3
Need to go to DJI official website to download, download link:
DJI Infrared Thermal Analysis Tool 3.0 - Download Center- DJI 大江 Innovation
1.2 TSDK
Need to go to DJI official website to download, download link:
DJI Thermal SDK - Download Center- DJI 大JI Innovations
2. A preview of relevant official documents about TSDK
Link: TSDK (Thermal SDK) FAQ Summary (continuously updated)-Developers-DJI Community
3. DJI Secondary Developer Answer Website
If you have technical questions about DJI products, you can also ask them on this website. Generally, DJI developers will answer them within 24 hours.
2. Start processing
1. Create a new project
Open visual studio 2017, create a new project and a cpp file, both named tsdk
1. Open the TSDK file
2. Open the sample file, copy the code in dji_irp.cpp to tsdk.cpp
Note: tsdk.cpp needs to link argagg.hpp, dirp_api.h and dirp_wrapper.h header files and libdirp.lib library files, and start linking later
3. Create a Libs file in the folder where tsdk.cpp is located, and create an icn folder and a lib folder in the Libs folder
4. Copy the files in the api folder under the tsdk-core directory of the downloaded TSDK to the icn folder
5. Put the files in the sample\argparse directory into the icn folder; copy all the .lib files in the tsdk-core/lib/windows/release_x64 directory to the lib folder
6. Select Debug and x64 on the top of the visual studio 2017 interface and then right-click the tsdk project to generate
Note: Here x64 must be selected correctly, otherwise an error will be reported later
After generation, click the x64 file in the same directory as the tsdk.sln file
6. Open x64\Debug, copy all .dll files and .ini files to the x64\Debug folder, and put them together with tsdk.exe.
Then start configuring
7. In the tsdk project, select Debug>tsdk Debug Properties>C/C++>General, set the additional include directory to the icn folder
NOTE: Make sure Platform above the screen is active (x64)
8. In the tsdk project, select Debug>tsdk Debug Properties>Linker>General, set the additional library directory to the lib folder
9. In the tsdk project, select Debug>tsdk Debug Properties>Linker>Input, set additional dependencies to libdirp.lib
This name can be typed by hand
Next, start programming in Pycharm, and finally generate a matrix storing temperature information
10. Call tsdk.exe through python code to process thermal imaging images in batches and generate .raw files that store temperature information.
# 通过python代码调用tsdk.exe,批量处理热成像图片,生成存储温度信息的.raw文件。
import os
tsdk = r'O:\desk\TSDK\tsdk\x64\Debug\tsdk.exe'
##tsdk.exe的储存位置
path ='O:\desk\DJI-red1/'
##拍摄的rJPG的储存位置
savepath = "O:\desk\DJI-red1/"
##处理结果的储存位置
os.makedirs(savepath, exist_ok=True)
distance = 25.0
emissivity = 0.95
humidity = 45
reflection = 51.8
##参数根据实际情况设置
def use_tsdk(tsdk, path, savepath):
print('start')
imgnamelist = os.listdir(path)
for imgname in imgnamelist:
if "T" in imgname:
##带T的图像是温度图像
portion = os.path.splitext(imgname)
coreimgname = portion[0]
param = '-s ' + path + imgname + ' -a measure -o ' + savepath + coreimgname + '.raw' + ' --distance ' + str(
distance) + ' --emissivity ' + str(emissivity) + ' --humidity ' + str(humidity) + '--reflection ' + str(
reflection)
##选择的模式是measure输出的结果是温度信息,不是原始信息
r_v = os.system(tsdk + ' ' + param)
print(r_v)
# 输出的为tsdk.exe运行的返回值
use_tsdk(tsdk, path, savepath)
11. Convert .raw to .tif
# 将.raw文件中的值除以10之后为温度值,转为.tif文件以备后续使用。python代码
import os
#调用opencv要用import cv2,用import opencv会报错
import cv2
import numpy as np
savepath = "O:\desk\DJI-red1/"
def raw_to_tif(path, rows, cols, channels):
print('to .tif start')
files = os.listdir(path)
for file in files:
portion = os.path.splitext(file)
if portion[1] == '.raw':
realPath = path + file
img = np.fromfile(realPath, dtype='uint16')
img = img / 10 ##除10之后为温度值
img = img.reshape(rows, cols, channels)
fileName = portion[0] + '.tif'
tif_fileName = os.path.join(path, fileName)
cv2.imwrite(tif_fileName, img, (int(cv2.IMWRITE_TIFF_COMPRESSION), 1))
os.remove(realPath) ##delete .raw file,如有需要,可以不删除
else:
print(file + ' it is not .raw file')
print('to .tif finsh')
raw_to_tif(savepath, 512, 640, 1)
12. Generate img temperature matrix
Comment out the bottom line of code
raw_to_tif(savepath, 512, 640, 1)
Then enter the following code
files = os.listdir(path)
for file in files:
portion = os.path.splitext(file)
if portion[1] == '.raw':
realPath = path + file
img = np.fromfile(realPath, dtype='uint16')
img = img / 10 ##除10之后为温度值
img = img.reshape(512, 640, 1)
fileName = portion[0] + '.tif'
tif_fileName = os.path.join(path, fileName)
cv2.imwrite(tif_fileName, img, (int(cv2.IMWRITE_TIFF_COMPRESSION), 1))
os.remove(realPath) ##delete .raw file,如有需要,可以不删除
13. Run the code, and then view the matrix corresponding to img
14. Use DJI Thermal Analysis Tool 3 to check the temperature of the pixel, and compare it with the generated temperature matrix to see if there is any difference