Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,7 @@ build

librir/libs/*

plugins/*
plugins/*


.vscode/*
61 changes: 48 additions & 13 deletions librir/video_io/IRMovie.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
import numpy as np
from librir.tools.utils import init_thermavip, unbind_thermavip_shared_mem
from librir.tools.FileAttributes import FileAttributes
from typing import List, Dict, Union

from librir.low_level.rir_video_io import (
enable_motion_correction,
load_motion_correction_file,
motion_correction_enabled,
)
from typing import List, Dict

from librir.low_level.rir_video_io import (
Expand Down Expand Up @@ -52,6 +59,10 @@ class IncoherentMetadata(Exception):
pass


class CalibrationNotFound(Exception):
pass


def create_pcr_header(rows, columns, frequency=50, bits=16):
pcr_header = np.zeros((256,), dtype=np.uint32)
pcr_header[2] = columns
Expand All @@ -68,7 +79,7 @@ class IRMovie(object):
_header_offset = 1024
__tempfile__ = None
handle = -1

_calibration_nickname_mapper = {"DL": "Digital Level"}
_roi_result_line = {"CEDIP": 240, "WEST": 512, "NIT": 256}

_SHAPES = {
Expand Down Expand Up @@ -151,17 +162,40 @@ def __init__(self, handle):

try:
self.calibration = "T"
except (IndexError, ValueError):
except (IndexError, ValueError, CalibrationNotFound):
logger.debug(
f"There is no temperature calibration. Switching back to Digital Level"
"There is no temperature calibration. Switching back to Digital Level"
)
self.calibration = "DL"

# if not ('Type' in self.attributes):
# d = self.attributes
# # inv_shapes = {v: k for k, v in self._SHAPES.items()}
# d['Type'] = self._SHAPES[self.image_size].encode('utf8')
# self.attributes = d
# # self._file_attributes.flush()
@property
def calibration(self):
return list(self._calibration_nickname_mapper.keys())[self._calibration_index]

@calibration.setter
def calibration(self, value: Union[str, int]):
searching_keys = self.calibrations + list(
self._calibration_nickname_mapper.keys()
)
_calibrations = self.calibrations
if isinstance(value, int):
if value >= len(_calibrations):
raise CalibrationNotFound(
f"Available calibrations : {self.calibrations}."
"Calibration index out of range"
)

self._calibration_index = value
return

if value not in searching_keys:
raise CalibrationNotFound(f"Available calibrations : {self.calibrations}")
try:
self._calibration_index = list(self._calibration_nickname_mapper).index(
value
)
except ValueError as e:
raise CalibrationNotFound(f"calibration {value} is not registered")

def __enter__(self):
"""
Expand Down Expand Up @@ -195,12 +229,11 @@ def close(self):
logger.warning(p_exc)

self.__tempfile__ = None



@property
def registration_file(self) -> Path:
"""
Returns the registration file name for this camera, and tries to download it
Returns the registration file name for this camera, and tries to download it
from ARCADE if not already done.
"""

Expand Down Expand Up @@ -283,7 +316,9 @@ def load_pos(self, pos, calibration=None):
"""Returns the image at given position using given calibration index (integer)"""
if calibration is None:
calibration = 0
res = load_image(self.handle, pos, calibration)

self.calibration = calibration
res = load_image(self.handle, pos, self._calibration_index)
self._frame_attributes_d[pos] = get_attributes(self.handle)
# self.frame_attributes = get_attributes(self.handle)
return res
Expand Down
8 changes: 8 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[pytest]
markers =
slow: marks tests as slow (deselect with '-m "not slow"')
concurrent: Concurrent and parallel jobs
h264
thermavip
io
needs_improvement
19 changes: 17 additions & 2 deletions src/video_io/IRFileLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "IRFileLoader.h"
#include "BaseCalibration.h"
#include "h264.h"
#include <mutex>

#include "HCCLoader.h"
#include "ZFile.h"
#include "Log.h"
Expand All @@ -31,8 +33,19 @@ namespace rir

std::string serializeTimePoint(const time_point& time, const std::string& format)
{
std::time_t tt = std::chrono::system_clock::to_time_t(time);
std::tm tm = *std::gmtime(&tt); //GMT (UTC)
static std::mutex mu;
std::tm* tmp = NULL;
std::tm tm;

{
std::unique_lock<std::mutex> lock(mu);
std::time_t tt = std::chrono::system_clock::to_time_t(time);
tmp = std::gmtime(&tt);
// Add check on std::gmtime result for invalid time point
if (!tmp)
return std::string();
tm = *tmp; //GMT (UTC)
}
//std::tm tm = *std::localtime(&tt); //Locale time-zone, usually UTC by default.
std::stringstream ss;
ss << std::put_time(&tm, format.c_str());
Expand Down Expand Up @@ -1140,9 +1153,11 @@ bool IRFileLoader::readImage(int pos, int calibration, unsigned short * pixels)
return true;
}


if (bin_read_image(m_data->file, pos, pixels, &time) != 0)
return false;


if (m_data->initOpticalTemperature == -1 && m_data->calib)
m_data->initOpticalTemperature = m_data->calib->opticalTemperature();
if (m_data->initSTEFITemperature == -1 && m_data->calib)
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@



# add_subdirectory(cpp)
add_subdirectory(cpp)
# add_subdirectory(python)
Empty file removed tests/__init__.py
Empty file.
4 changes: 2 additions & 2 deletions tests/cpp/west/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ foreach (test ${TestsToRun})
endforeach ()

# add_executable(test_call_ts test_call_ts.cpp)
add_dependencies(CommonCxxTests west)
#add_dependencies(CommonCxxTests west)


target_include_directories(CommonCxxTests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(CommonCxxTests west video_io tools geometry signal_processing)# ${FFMPEG_LIBS})
target_link_libraries(CommonCxxTests video_io tools geometry signal_processing)# ${FFMPEG_LIBS})

# add_test(NAME test_call_ts
# WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/out
Expand Down
25 changes: 1 addition & 24 deletions tests/cpp/west/test_call_ts.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@
//#include "h264.h"
#include "IRLoader.h"
#include "west.h"
//#include "geometry.h"
//#include "Primitives.h"
//#include "ReadFileChunk.h"

using namespace rir;

int test_call_ts(int argc, char** const argv)
{
double x[1000] = {0};
double y[1000] = {0};
int length = 0;
int tot_length = 0;
int signal_count = 0;
char y_unit[200] = "";
char date[200] = "";

int ret = ts_read_signal_group(57730, "GMAG_STRIKE", x, y, &tot_length, &length, &signal_count, y_unit, date);
if (ret < 0)
{
ret = ts_read_signal_group(57730, "GMAG_STRIKE", x, y, &tot_length, &length, &signal_count, y_unit, date);

}
// char id[200];
// int ret = get_full_cam_identifier_from_partial(55567, (char*)"WA", id);
return ret;
return 0;
}
14 changes: 10 additions & 4 deletions tests/cpp/west/test_full.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#include "h264.h"
#include "IRLoader.h"
#include "west.h"

#include "video_io.h"
#include "geometry.h"
#include "Primitives.h"
#include "ReadFileChunk.h"
#include "TopC5.h"
#include "IRFileLoader.h"
#include "tools.h"
#include "TemporaryDir.h"

#include "HCCLoader.h"

#include <iostream>
Expand All @@ -18,6 +17,13 @@ using namespace rir;

int test_full(int argc, char** const argv)
{
{
rir::IRFileLoader l;
bool ok = l.open("C:/Users/VM213788/Desktop/tmpf602soaj");
std::vector<unsigned short> img(640 * 515);
ok = l.readImage(0, 0, img.data());
bool stop = true;
}
std::vector<unsigned short> img(640 * 512);
std::ifstream fin("C:/src/test_build/librir/video.bin", std::ios::binary);
if (!fin)
Expand Down
Loading