126 lines
4.2 KiB
Python
126 lines
4.2 KiB
Python
import json
|
|
import argparse
|
|
from datetime import datetime
|
|
|
|
|
|
def now_str():
|
|
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
|
|
def load_json(path):
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
return json.load(f)
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--camera_json", default="calibration/sensor_calibration.json")
|
|
parser.add_argument("--fusion_json", default="calibration/manual_offsets.json")
|
|
parser.add_argument("--radiometric_json", default="")
|
|
parser.add_argument("--out", default="calibration/module_params.json")
|
|
args = parser.parse_args()
|
|
|
|
cam_data = load_json(args.camera_json)
|
|
fusion_data = load_json(args.fusion_json)
|
|
|
|
radiometric_data = {}
|
|
if args.radiometric_json:
|
|
radiometric_data = load_json(args.radiometric_json)
|
|
|
|
# =========================
|
|
# CAMERA SETTINGS
|
|
# =========================
|
|
camera_settings = cam_data.get("camera_settings")
|
|
if not isinstance(camera_settings, dict):
|
|
raise RuntimeError("camera_json sem camera_settings válido")
|
|
|
|
# =========================
|
|
# RGB CALIBRATION (NOVO)
|
|
# =========================
|
|
rgb_calibration = cam_data.get("rgb_calibration")
|
|
|
|
if not isinstance(rgb_calibration, dict):
|
|
rgb_calibration = {
|
|
"enabled": False,
|
|
"gains": {
|
|
"R": 1.0,
|
|
"G": 1.0,
|
|
"B": 1.0,
|
|
}
|
|
}
|
|
|
|
# =========================
|
|
# RADIOMETRIC
|
|
# =========================
|
|
radiometric_config = radiometric_data.get("radiometric_config")
|
|
|
|
if not isinstance(radiometric_config, dict):
|
|
radiometric_config = cam_data.get("radiometric_config")
|
|
|
|
if not isinstance(radiometric_config, dict):
|
|
radiometric_config = {
|
|
"interval_s": 0.5,
|
|
"strip_y0_pct": 0.95,
|
|
"strip_y1_pct": 1.0,
|
|
"patch_x0_pct": 0.35,
|
|
"patch_x1_pct": 0.75,
|
|
"target_mean": 0.70,
|
|
"deadband": 0.03,
|
|
"alpha": 0.18,
|
|
"exp_min_us": 100,
|
|
"exp_max_us": 80000,
|
|
"gain_min": 1.0,
|
|
"gain_max": 8.0,
|
|
"verbose": True,
|
|
"exp_apply_threshold_us": 50,
|
|
"gain_apply_threshold": 0.02,
|
|
}
|
|
|
|
# =========================
|
|
# FUSION CONFIG
|
|
# =========================
|
|
fusion_config = {
|
|
"alignment_mode": fusion_data.get("alignment_mode", "manual_affine"),
|
|
"baseline_mm": fusion_data.get("baseline_mm", 75.0),
|
|
|
|
# 🔥 AJUSTE IMPORTANTE
|
|
"reference_camera": fusion_data.get("reference_camera", "rgb"),
|
|
|
|
"manual_offsets": fusion_data.get("manual_offsets", {}),
|
|
"homographies": fusion_data.get("homographies", {}),
|
|
"crop_valid_common": fusion_data.get("crop_valid_common", True),
|
|
"resize_after_crop": fusion_data.get("resize_after_crop", True),
|
|
"target_size": fusion_data.get("target_size", None),
|
|
}
|
|
|
|
# =========================
|
|
# MODULE PARAMS FINAL
|
|
# =========================
|
|
module_params = {
|
|
"schema": "multispec_module_params_v2", # 👈 versão nova
|
|
"saved_at": now_str(),
|
|
|
|
"frame_type": cam_data.get("frame_type", fusion_data.get("frame_type", "RAW_BRUTO")),
|
|
"capture_mode_requested": cam_data.get("capture_mode_requested", "AUTO"),
|
|
"capture_mode_effective": cam_data.get("capture_mode_effective", "AUTO"),
|
|
"raw_policy": cam_data.get("raw_policy", "allow_single"),
|
|
|
|
"sensor_width": cam_data.get("sensor_width", fusion_data.get("sensor_width")),
|
|
"sensor_height": cam_data.get("sensor_height", fusion_data.get("sensor_height")),
|
|
"bayer_pattern": cam_data.get("bayer_pattern", fusion_data.get("bayer_pattern", "GBRG")),
|
|
|
|
# 🔥 BLOCOS PRINCIPAIS
|
|
"camera_settings": camera_settings,
|
|
"fusion_config": fusion_config,
|
|
"radiometric_config": radiometric_config,
|
|
"rgb_calibration": rgb_calibration, # 👈 NOVO
|
|
}
|
|
|
|
with open(args.out, "w", encoding="utf-8") as f:
|
|
json.dump(module_params, f, ensure_ascii=False, indent=2)
|
|
|
|
print(f"[OK] module_params gerado em: {args.out}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |