summaryrefslogtreecommitdiff
path: root/utils/tuning/libtuning/macbeth.py
diff options
context:
space:
mode:
authorStefan Klug <stefan.klug@ideasonboard.com>2024-06-06 11:58:33 +0200
committerStefan Klug <stefan.klug@ideasonboard.com>2024-07-05 22:38:00 +0200
commitaa02706a34474eb108cf99f94396341e2709f045 (patch)
treef1066097a7dc0c4739882ee91e2f1cbb893d7aec /utils/tuning/libtuning/macbeth.py
parentb1f3b3f08d365dc087508b573dd095808267e640 (diff)
libtuning: Migrate prints to python logging framework
In ctt_ccm.py the logging functionality of the Cam object was used. As we don't want to port over that class, it needs to be replaced anyways. While at it, also replace the eprint function as it doesn't add any value over the logging framework and misses the ability for easy log formatting. For nice output formatting add the coloredlogs library. Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
Diffstat (limited to 'utils/tuning/libtuning/macbeth.py')
-rw-r--r--utils/tuning/libtuning/macbeth.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/utils/tuning/libtuning/macbeth.py b/utils/tuning/libtuning/macbeth.py
index 265a33d6..28051de8 100644
--- a/utils/tuning/libtuning/macbeth.py
+++ b/utils/tuning/libtuning/macbeth.py
@@ -13,12 +13,15 @@ import os
from pathlib import Path
import numpy as np
import warnings
+import logging
from sklearn import cluster as cluster
from .ctt_ransac import get_square_verts, get_square_centres
from libtuning.image import Image
+logger = logging.getLogger(__name__)
+
# Reshape image to fixed width without distorting returns image and scale
# factor
@@ -374,7 +377,7 @@ def get_macbeth_chart(img, ref_data):
# Catch macbeth errors and continue with code
except MacbethError as error:
- eprint(error)
+ logger.warning(error)
return (0, None, None, False)
@@ -497,7 +500,7 @@ def find_macbeth(img, mac_config):
coords_fit = coords
if cor < 0.75:
- eprint(f'Warning: Low confidence {cor:.3f} for macbeth chart in {img.path.name}')
+ logger.warning(f'Low confidence {cor:.3f} for macbeth chart')
if show:
draw_macbeth_results(img, coords_fit)
@@ -510,18 +513,18 @@ def locate_macbeth(image: Image, config: dict):
av_chan = (np.mean(np.array(image.channels), axis=0) / (2**16))
av_val = np.mean(av_chan)
if av_val < image.blacklevel_16 / (2**16) + 1 / 64:
- eprint(f'Image {image.path.name} too dark')
+ logger.warning(f'Image {image.path.name} too dark')
return None
macbeth = find_macbeth(av_chan, config['general']['macbeth'])
if macbeth is None:
- eprint(f'No macbeth chart found in {image.path.name}')
+ logger.warning(f'No macbeth chart found in {image.path.name}')
return None
mac_cen_coords = macbeth[1]
if not image.get_patches(mac_cen_coords):
- eprint(f'Macbeth patches have saturated in {image.path.name}')
+ logger.warning(f'Macbeth patches have saturated in {image.path.name}')
return None
return macbeth