首先是在win10下实现:
import ctypes
# 加载动态链接库
lib_dirp = ctypes.CDLL('./dji_thermal_sdk/tsdk-core/lib/windows/release_x64/libdirp.dll')
# 定义函数的参数和返回类型
lib_dirp.dirp_create_from_rjpeg.restype = ctypes.c_int
lib_dirp.dirp_create_from_rjpeg.argtypes = [ctypes.POINTER(ctypes.c_uint8), ctypes.c_int, ctypes.POINTER(ctypes.c_void_p)]
lib_dirp.dirp_destroy.argtypes = [ctypes.c_void_p]
lib_dirp.dirp_measure.restype = ctypes.c_int
lib_dirp.dirp_measure.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_int16), ctypes.c_int]
lib_dirp.dirp_measure_ex.restype = ctypes.c_int
lib_dirp.dirp_measure_ex.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_float), ctypes.c_int]
# 读取 R-JPEG 文件内容
with open('.\\dji_thermal_sdk\\dataset\\H20N\\DJI_0001_R.JPG', 'rb') as file:
rjpeg_data = file.read()
data_size = len(rjpeg_data)
# 创建 DIRP 的句柄
dirp_handle = ctypes.c_void_p()
# 调用 dirp_create_from_rjpeg 函数
result = lib_dirp.dirp_create_from_rjpeg(ctypes.cast(rjpeg_data, ctypes.POINTER(ctypes.c_uint8)), data_size, ctypes.byref(dirp_handle))
if result != 0:
print("Error creating DIRP from rjpeg data")
else:
print("DIRP created successfully")
# 分配内存以存储温度图像数据
image_width = 640
image_height = 512
image_size = image_width * image_height
# 为 dirp_measure 分配内存
temp_image_int16 = (ctypes.c_int * image_size)()
# 为 dirp_measure_ex 分配内存
temp_image_float = (ctypes.c_float * image_size)()
# 获取 temp_image_int16 的指针
temp_image_int16_ptr = ctypes.cast(temp_image_int16, ctypes.POINTER(ctypes.c_int16))
# 获取 temp_image_float 的指针
temp_image_float_ptr = ctypes.cast(temp_image_float, ctypes.POINTER(ctypes.c_float))
# 调用 dirp_measure 函数
result_measure = lib_dirp.dirp_measure(dirp_handle, temp_image_int16_ptr, image_size*2)
if result_measure != 0:
print("Error measuring DIRP with int16")
else:
print("DIRP measured successfully with int16")
# 调用 dirp_measure_ex 函数
ret = lib_dirp.dirp_measure_ex(dirp_handle, temp_image_float_ptr, image_size*4)
if ret != 0:
print("Error measuring DIRP with float")
else:
print("DIRP measured successfully with float")
# # 遍历 temp_image_float 数组以找到最大温度
# max_temperature = max(temp_image_float)
# # 打印最大温度
# print(f"Maximum temperature: {max_temperature}°C")
# 调用 dirp_destroy 函数
lib_dirp.dirp_destroy(dirp_handle)
print("DIRP destroyed successfully")
将以上程序保存为.py文件,并与dji_thermal_sdk文件放在同一文件夹直接运行即可。(dji_thermal_sdk可以在大疆官网下载)
接下来在linux系统下调用SDK:
1.安装VMware 虚拟机
2.在虚拟机中安转linux(https://blog.csdn.net/EsDeath_99/article/details/136361704);
我安装的是centos7。(对应的ISO文件可以在官网下载)
3.安装好后是自带python的,但我额外安装了python3,在终端运行:
sudo yum update
sudo yum install python3
4.上述都完成后,将以下代码和dji_thermal_sdk文件放在同一文件夹“wenjian”,并将文件夹“wenjian”放在/usr/local/ 中。在终端运行 python3 your.py。
如果出现:
File “/usr/lib64/python2.7/ctypes/init.py”, line 360, in init
self._handle = _dlopen(self._name, mode)
OSError: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21’ not found (required by
可按照以下步骤处理:(https://blog.csdn.net/jaber_chen/article/details/124715913)
cd /usr/local/lib64/
下载最新版本的下载最新版本的libstdc.so_.6.0.26
wget http://www.vuln.cn/wp-content/uploads/2019/08/libstdc.so_.6.0.26.zip
解压
unzip libstdc.so_.6.0.26.zip
将下载的最新版本拷贝到 /usr/lib64
cp libstdc++.so.6.0.26 /usr/lib64
cd /usr/lib64
查看 /usr/lib64下libstdc++.so.6链接的版本
ls -l | grep libstdc++
删除原先的软连接(不放心可以备份)
rm libstdc++.so.6
使用最新的库建立软连接
ln -s libstdc++.so.6.0.26 libstdc++.so.6
查看新版本,成功
strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX
然后再次在终端运行 python3 your.py,发现运行成功。
如果还有问题:(运行下边命名查看具体错误,然后解决)
1.使用strace进行系统调用跟踪:
使用strace工具来跟踪程序运行时的系统调用。这可以帮助您发现潜在的问题,比如文件访问错误、库加载错误等。
strace -e open,read,close,mmap,brk,munmap,ioctl python your_script.py
查看错误日志:
检查系统日志(如/var/log/messages)或使用dmesg命令来查看可能的错误信息。
2.使用调试工具:
使用如gdb这样的调试工具来运行您的Python脚本,以便在运行时检查变量的状态和程序的行为。
gdb --args python your_script.py