This commit is contained in:
sebseb7
2025-12-21 23:08:10 +01:00
parent a913162b6e
commit 4ed5bc3415
2 changed files with 19 additions and 5 deletions

View File

@@ -376,10 +376,10 @@ apply_camera_settings() {
local applied=0
for ctrl in $keys; do
local value
value=$(echo "$values" | jq -r ".[\"$ctrl\"] // empty")
value=$(echo "$values" | jq -r ".\"$ctrl\" // empty")
if [[ -n "$value" && "$value" != "null" ]]; then
if v4l2-ctl -d "$VIDEO_DEVICE" --set-ctrl="${ctrl}=${value}" 2>/dev/null; then
((applied++))
((applied++)) || true
fi
fi
done

View File

@@ -147,15 +147,18 @@ app.post('/upload', authenticate, upload.single('image'), async (req, res) => {
const settings = allSettings[storageKey] || {};
// Check if we need to modify the image
if (settings.rotation || settings.crop) {
const shouldRotate = settings.rotation && settings.rotation !== 0;
const shouldCrop = settings.crop && settings.crop.width > 0 && settings.crop.height > 0;
if (shouldRotate || shouldCrop) {
console.log(`Applying transformations for ${cameraId}:`, { rotation: settings.rotation, crop: settings.crop });
let pipeline = sharp(req.file.path);
if (settings.rotation) {
if (shouldRotate) {
pipeline = pipeline.rotate(settings.rotation);
}
if (settings.crop) {
if (shouldCrop) {
// crop format: { left, top, width, height }
pipeline = pipeline.extract(settings.crop);
}
@@ -542,8 +545,19 @@ app.post('/settings/:cameraId/available', authenticate, express.json(), (req, re
const allSettings = loadCameraSettings();
const existing = allSettings[storageKey] || {};
// Default config values for new entries
const defaultConfig = {
rotation: 0,
crop: { left: 0, top: 0, width: 0, height: 0 },
ocr: { enabled: false, minval: 0, maxval: 9999 },
chartLabel: null,
insertBrightnessToDb: false
};
// Preserve existing configured values, but update available controls
allSettings[storageKey] = {
// Start with defaults, then overlay existing config
...defaultConfig,
...existing,
availableControls: controls,
// Merge current camera values as defaults if no values configured yet