Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 0.0.2 instead.
Reason given by maintainers: it is not friendly to the developer who know a little C++

DJI Thermal SDK

use ctypes to capsulate the DJI Thermal SDK so that we can directly use python to process thermal images.

import nbdev
from dji_thermal_sdk.dji_sdk import *
import dji_thermal_sdk.dji_sdk as DJI
import ctypes as CT
from ctypes import *
import os

This version of DJI Thermal SDK is 1.3, which was published on 05/15/2022

Install

pip install dji_thermal_sdk

Load DLL

Normally, DJI SDK DLLs include libdirp.dll, libv_dirp.dll, libv_girp.dll, libv_iirp.dll, libv_list.ini.

you should put all the dlls and your codes in a same folder.

The reason that the following codes are commented is because it can't pass the GitHub CI test, but it works well.

DJI dlls use C++, and when we use ctypes to invoke them, python complier will pop out 'invalid ELF header' error.

'''
try:
    _libdirp = cdll.LoadLibrary("./libdirp.dll")
    DJI.set_dirp_dll(_libdirp)
except FileNotFoundError as err:
    print(err)
print(DJI._libdirp)
'''
<CDLL 'D:\LYU\Code\git_repository\dji_thermal_sdk\libdirp.dll', handle 7ffe6f310000 at 0x1aa05b61850>





True

Get the handle of a R-JPEG image

DIRP_HANDLE is a void pointer, and it has been definded.
you can get it by package.DIRP_HANDLE

nbdev.show_doc(dirp_create_from_rjpeg)

dirp_create_from_rjpeg[source]

dirp_create_from_rjpeg(data, size, ph)

Parameters: [in] data: R-JPEG binary data buffer pointer [in] size: R-JPEG binary data buffer size in bytes [out]ph : DIRP API handle pointer - reminder: use two-level pointer to assign value to one-level pointer Return: int return code dirp_ret_code_e

'''
rd = r"dataset\Deer_Goats_Unsure__2022-02-02__02-42-12(2).JPG"
with open(rd, 'rb') as f:
    content = f.read()
    print(len(content))
# method1 to get the file size
print(f"File size: {os.path.getsize(rd)}")
# method 2 to get the file size
file_stat = os.stat(rd)
size = c_int32(file_stat.st_size)
print(f"File size: {size}")

# the method to create a string buffer, which is important.
rjpeg_data = CT.create_string_buffer(len(content))
rjpeg_data.value = content
print(f"rjpeg_data: {rjpeg_data}")

# test the function to create a handle of an image
ret = dirp_create_from_rjpeg(rjpeg_data,size, CT.byref(DIRP_HANDLE))
print(f'ret = {ret}')
if ret == 0:
    print("successfully get the r-jpeg handle.")
#
print(f"DIRP_HANDLE: {DIRP_HANDLE}  address: {hex(DIRP_HANDLE.value)} ")
'''

Get the version of API

nbdev.show_doc(dirp_get_api_version)

dirp_get_api_version[source]

dirp_get_api_version(version)

Parameters: [out] version DIRP API version information pointer Return: int return code dirp_ret_code_e

nbdev.show_doc(dirp_api_version_t)

class dirp_api_version_t[source]

dirp_api_version_t() :: Structure

API version structure definition

'''
jpeg_version = dirp_api_version_t() 
ret = dirp_get_api_version(CT.byref(jpeg_version))
if ret == DIRP_SUCCESS:
    print("Success")
#
print(f"jpeg_version.api: \t {jpeg_version.api}")
print(f"jpeg_version.magic: \t {jpeg_version.magic}")
'''

Get Color Bar

nbdev.show_doc(dirp_get_color_bar)

dirp_get_color_bar[source]

dirp_get_color_bar(h, color_bar)

Parameters: [in] h: DIRP API handle [out] color_bar: ISP color bar parameters pointer Return: int return code dirp_ret_code_e

nbdev.show_doc(dirp_color_bar_t)

class dirp_color_bar_t[source]

dirp_color_bar_t() :: Structure

Color bar parameters structure definition

'''
jpeg_color_bar = dirp_color_bar_t()
ret = dirp_get_color_bar(DIRP_HANDLE, CT.byref(jpeg_color_bar))
if ret == DIRP_SUCCESS:
    print("Success")
print(f"jpeg_color_bar.high: \t {jpeg_color_bar.high}")
print(f"jpeg_color_bar.low: \t {jpeg_color_bar.low}")
print(f"jpeg_color_bar.manual_enable: \t {jpeg_color_bar.manual_enable}")
'''

Get the resolution of a R-JPEG image

nbdev.show_doc(dirp_create_from_rjpeg)

nbdev.show_doc(dirp_get_rjpeg_resolution)

dirp_get_rjpeg_resolution[source]

dirp_get_rjpeg_resolution(h, rjpeg_info)

Get R-JPEG image resolution information. Parameters [in]h: DIRP API handle [out]rjpeg_info: R-JPEG basic information pointer Returns int return code dirp_ret_code_e

nbdev.show_doc(dirp_resolution_t)

class dirp_resolution_t[source]

dirp_resolution_t() :: Structure

The image size structure definition

'''
rjpeg_resolution = dirp_resolution_t()
ret = dirp_get_rjpeg_resolution(DIRP_HANDLE, CT.byref(rjpeg_resolution))
print(f'ret = {ret}')
if ret == 0:
    print("successfully get the resolution.")

out = f'Height: {rjpeg_resolution.height}, width: {rjpeg_resolution.width}'
out
'''

Set Pseudo Color

nbdev.show_doc(dirp_set_pseudo_color)
'''
ret = dirp_set_pseudo_color(DIRP_HANDLE, c_int(0))
if ret == DIRP_SUCCESS:
    print("Success")
else:
    print(f"Error: ret={ret}")
'''

Transform a thermal image by a specific palette

nbdev.show_doc(dirp_process)
'''
import matplotlib.pyplot as plt
import numpy as np
size = rjpeg_resolution.height * rjpeg_resolution.width * 3 * CT.sizeof(c_uint8)
raw_image_buffer = CT.create_string_buffer(size)
print(raw_image_buffer.raw[100])
ret = dirp_process(DIRP_HANDLE,byref(raw_image_buffer), size)
if ret == DIRP_SUCCESS:
    print("Success")
else:
    print(f"Error: ret={ret}")
#
raw_file_path = os.path.splitext(rd)[0] + ".raw"
print(raw_file_path)
with open(raw_file_path, 'wb') as f:
    f.write(raw_image_buffer.raw)
#
if os.path.exists(raw_file_path):
    print(f"Success! file size: {os.path.getsize(raw_file_path)}")
else:
    print("Error")
#
with open(raw_file_path, encoding='cp1252') as fin:
    img = np.fromfile(fin, dtype = np.uint8)
    print(img.shape)
    img.shape = (512,640,3)
    #original = Image.fromarray(img)
#

fig = plt.figure(figsize=(10,8))
plt.imshow(img, cmap='gray')
'''

Metadata

Release files for dji-thermal-sdk 1.3.20220517

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dji-thermal-sdk 1.3.20220517
File Size Uploaded Provenance Actions
dji_thermal_sdk-1.3.20220517.tar.gz 17.1 kB Without provenance Details for dji_thermal_sdk-1.3.20220517.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dji-thermal-sdk 1.3.20220517
File Interpreter ABI Platform Actions
dji_thermal_sdk-1.3.20220517-py3-none-any.whl Python 3 none any Details for dji_thermal_sdk-1.3.20220517-py3-none-any.whl

Total release size: 30.4 kB

Release files / dji_thermal_sdk-1.3.20220517.tar.gz

Download URL dji_thermal_sdk-1.3.20220517.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e024e21f836aa6ee385e382806df4b912a5ad937647e477246fb7b664c866c14
BLAKE2b-256 checksum
How to use checksums
a0900803e60c622671e1cbcfd072c93487b09e3601003a63dd5c224892043d9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

Release files / dji_thermal_sdk-1.3.20220517-py3-none-any.whl

Download URL dji_thermal_sdk-1.3.20220517-py3-none-any.whl
Size 13.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1400f2420e55bbd3a4fa6afaa48383d46e7bf91d16d1f05029f46a3b7a8f8215
BLAKE2b-256 checksum
How to use checksums
e91a2c2d4961e73c2d2c90761876fd48b02ca725f1d150cc02876fa602478e91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

Security for dji-thermal-sdk 1.3.20220517

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page