Skip to content

Commit

Permalink
Merge pull request #37 from nemocrys:arvedes/issue34
Browse files Browse the repository at this point in the history
Debug Optris camera on Windows, update pyOptris
  • Loading branch information
arvedes authored Feb 16, 2023
2 parents b137997 + e415dec commit 6a57260
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 30 deletions.
3 changes: 3 additions & 0 deletions config_template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,7 @@ devices:
emissivity: 0.95
transmissivity: 1.0
T-ambient: -1000 # Ambient temperature, setting invalid values (below -273,15 degrees) forces the library to take its own measurement values. # TODO what does that mean?
# library_path: C:/irDirectSDK/sdk/x64/libirimager.dll # Custom path to dll / so. Defaults to "/usr/lib/libirdirectsdk.so"
# formats-path: C:/irDirectSDK # Custom path to Formats.def. Defaults to "/usr/share/libirimager"
# cali-path: C:/irDirectSDK/cali # Custom path to calibration files. Defaults to "/usr/share/libirimager/cali"
# comment: your comment for nomad ELN
28 changes: 15 additions & 13 deletions multilog/devices/optris_ip640.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,20 @@ def __init__(self, config, name="OptrisIP640", xml_dir="./"):
logger.info(f"{self.name} - transmissivity {self.transmissivity}")
self.t_ambient = config["T-ambient"]
logger.info(f"{self.name} - T-ambient {self.t_ambient}")
if "formats-path" in config:
formats_path = config["formats-path"]
else:
formats_path = "/usr/share/libirimager"
if "cali-path" in config:
cali_path = config["cali-path"]
else:
cali_path = "/usr/share/libirimager/cali"
xml = f"""<?xml version="1.0" encoding="UTF-8"?>
<imager xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<serial>{config['serial-number']}</serial> <!-- Provide serial number, if you attach more than one camera -->
<videoformatindex>0</videoformatindex> <!-- index of the used video format (USB endpoint) -->
<formatspath>/usr/share/libirimager</formatspath>
<calipath>/usr/share/libirimager/cali</calipath>
<dppath>/root/.irimager/Cali</dppath>
<formatspath>{formats_path}</formatspath>
<calipath>{cali_path}</calipath>
<!-- Uncomment the following lines to specify user-defined parameters for the desired optic
and temperature range. Be aware to specify meaningful parameters.
See documentation for further information: http://evocortex.com/libirimager2/html/index.html
Expand Down Expand Up @@ -77,16 +84,11 @@ def __init__(self, config, name="OptrisIP640", xml_dir="./"):
self.xml_file = f"{xml_dir}/{config['serial-number']}.xml"
with open(self.xml_file, "w", encoding="utf-8") as f:
f.write(xml)
try:
optris.usb_init(
self.xml_file
) # This often fails on the first attempt, therefore just repeat in case of an error.
except Exception as e:
print(
f"Couldn't setup OptrisIP64.\n{traceback.format_exc()}\nTrying again..."
)
logging.error(traceback.format_exc())
optris.usb_init(self.xml_file)
if "library_path" in config:
optris.load_DLL(config["library_path"])
else:
optris.load_DLL(None)
optris.usb_init(self.xml_file)
optris.set_radiation_parameters(
self.emissivity, self.transmissivity, self.t_ambient
)
Expand Down
38 changes: 21 additions & 17 deletions multilog/pyOptris/direct_binding.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
import sys
import ctypes
from typing import Tuple
import sys
from enum import Enum
from typing import Optional, Tuple

import numpy as np

DEFAULT_WIN_PATH = "..//..//irDirectSDK//sdk//x64//libirimager.dll"
DEFAULT_LINUX_PATH = "/usr/lib/libirdirectsdk.so"
lib = None

# Function to load the DLL accordingly to the OS
def load_DLL(dll_path: str):
def load_DLL(dll_path: str) -> None:
global lib
if sys.platform == "linux":
path = dll_path if dll_path is not None else DEFAULT_LINUX_PATH
lib = ctypes.CDLL(DEFAULT_LINUX_PATH)
lib = ctypes.CDLL(path)

elif sys.platform == "win32":
path = dll_path if dll_path is not None else DEFAULT_WIN_PATH
lib = ctypes.CDLL(path)


# Load DLL
load_DLL(None)

#
# @brief Initializes an IRImager instance connected to this computer via USB
# @param[in] xml_config path to xml config
Expand All @@ -32,7 +30,9 @@ def load_DLL(dll_path: str):
#
# __IRDIRECTSDK_API__ int evo_irimager_usb_init(const char* xml_config, const char* formats_def, const char* log_file);
#
def usb_init(xml_config: str, formats_def: str = None, log_file: str = None) -> int:
def usb_init(
xml_config: str, formats_def: Optional[str] = None, log_file: Optional[str] = None
) -> int:
return lib.evo_irimager_usb_init(
xml_config.encode(),
None if formats_def is None else formats_def.encode(),
Expand Down Expand Up @@ -149,15 +149,19 @@ def get_palette_image(width: int, height: int) -> np.ndarray:
#
# __IRDIRECTSDK_API__ int evo_irimager_get_thermal_palette_image(int w_t, int h_t, unsigned short* data_t, int w_p, int h_p, unsigned char* data_p );
#
def get_thermal_palette_image(width: int, height: int) -> Tuple[int, int]:
w = ctypes.byref(ctypes.c_int(width))
h = ctypes.byref(ctypes.c_int(height))
thermalData = np.empty((height, width), dtype=np.uint16)
paletteData = np.empty((height, width, 3), dtype=np.uint8)
def get_thermal_palette_image(
t_width: int, t_height: int, p_width: int, p_height
) -> Tuple[np.ndarray, np.ndarray]:
t_w = ctypes.byref(ctypes.c_int(t_width))
t_h = ctypes.byref(ctypes.c_int(t_height))
p_w = ctypes.byref(ctypes.c_int(p_width))
p_h = ctypes.byref(ctypes.c_int(p_height))
thermalData = np.empty((t_height, t_width), dtype=np.uint16)
paletteData = np.empty((p_height, p_width, 3), dtype=np.uint8)
thermalDataPointer = thermalData.ctypes.data_as(ctypes.POINTER(ctypes.c_ushort))
paletteDataPointer = paletteData.ctypes.data_as(ctypes.POINTER(ctypes.c_ubyte))
_ = lib.evo_irimager_get_thermal_palette_image(
w, h, thermalDataPointer, w, h, paletteDataPointer
t_w, t_h, thermalDataPointer, p_w, p_h, paletteDataPointer
)
return (thermalData, paletteData)

Expand Down Expand Up @@ -197,7 +201,7 @@ class ColouringPalette(Enum):


def set_palette(colouringPalette: ColouringPalette) -> int:
return lib.evo_irimager_set_palette(colouringPalette)
return lib.evo_irimager_set_palette(colouringPalette.value)


#
Expand All @@ -220,7 +224,7 @@ class PaletteScalingMethod(Enum):


def set_palette_scale(paletteScalingMethod: PaletteScalingMethod) -> int:
return lib.evo_irimager_set_palette_scale(paletteScalingMethod)
return lib.evo_irimager_set_palette_scale(paletteScalingMethod.value)


#
Expand All @@ -236,7 +240,7 @@ class ShutterMode(Enum):


def set_shutter_mode(shutterMode: ShutterMode) -> int:
return lib.evo_irimager_set_shutter_mode(shutterMode)
return lib.evo_irimager_set_shutter_mode(shutterMode.value)


#
Expand Down

0 comments on commit 6a57260

Please sign in to comment.