From 4127cf127d19d73004f7529ce1c15bc2e68428b1 Mon Sep 17 00:00:00 2001 From: TRex22 Date: Sat, 1 May 2021 11:15:25 +0200 Subject: [PATCH 1/5] Add in awb options :hammer: --- README.md | 3 --- src/camera_handler.py | 13 +++++++++++++ src/main.py | 5 ++++- src/menu_handler.py | 2 ++ src/overlay_handler.py | 11 ++++++++--- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 726baf5d..c8245178 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,6 @@ https://torger.se/anders/dcamprof.html#download - Write actual tests - Histogram and analysis tools - RAW sensor capture: https://raspberrypi.stackexchange.com/questions/51191/how-can-i-stop-the-overlay-of-images-between-my-pi-camera-and-flir-camera - - ISO - - Shutter Speed - Resolution (FPS as label) - FPS option (wrt resolution) - Menus @@ -70,7 +68,6 @@ https://torger.se/anders/dcamprof.html#download - brightness - saturation - ev compression - - exposure mode - awb - auto white balance - image effect - colour effect diff --git a/src/camera_handler.py b/src/camera_handler.py index d67852b5..5eb7e12a 100644 --- a/src/camera_handler.py +++ b/src/camera_handler.py @@ -20,6 +20,7 @@ def auto_mode(camera, config): camera.iso = config["default_iso"] camera.exposure_mode = config["default_exposure_mode"] camera.shutter_speed = config["default_shutter_speed"] + camera.awb = config["default_awb"] overlay_handler.display_text(camera, '', config) print(f'auto mode!') @@ -73,6 +74,18 @@ def adjust_shutter_speed(camera, config): overlay_handler.display_text(camera, '', config) print(f'shutter_speed: {config["shutter_speed"]}') +def adjust_awb(camera, config): + idex = config["available_awb"].index(config["awb"]) + 1 + + if idex < len(config["available_awb"]): + config["awb"] = config["available_awb"][idex] + else: + config["awb"] = config["default_awb"] + + camera.awb = config["awb"] + overlay_handler.display_text(camera, '', config) + print(f'awb: {config["awb"]}') + def set_hdr(camera, config): config["hdr"] = not config["hdr"] overlay_handler.display_text(camera, '', config) diff --git a/src/main.py b/src/main.py index acac9e9c..66f474fa 100644 --- a/src/main.py +++ b/src/main.py @@ -99,7 +99,10 @@ "available_shutter_speeds": [0, 100, 500, 1000, 2000, 4000, 8000, 16667, 33333, 66667, 125000, 250000, 500000, 1000000, 2000000, 5000000, 10000000, 15000000, 20000000, 25000000, 30000000, 35000000, 40000000], "shutter_speed": 0, "default_shutter_speed": 0, - "available_menu_items": ["auto", "exposure_mode", "iso", "shutter_speed", "hdr", "video", "resolution", "encoding"], + "available_awb": ['auto', 'off', 'sunlight', 'cloudy', 'shade', 'tungsten', 'fluorescent', 'incandescent', 'flash', 'horizon'], + "awb": 'auto', + "default_awb": 'auto', # "awb_gains": 0.0 - 8.0 (), + "available_menu_items": ["auto", "exposure_mode", "iso", "shutter_speed", "AWB", "hdr", "video", "resolution", "encoding"], "menu_item": "auto", "default_menu_item": "auto", "hdr": False, diff --git a/src/menu_handler.py b/src/menu_handler.py index ac7610ea..fb4c4bb9 100644 --- a/src/menu_handler.py +++ b/src/menu_handler.py @@ -21,6 +21,8 @@ def select_option(camera, config): camera_handler.adjust_iso(camera, config) if config["menu_item"] == "shutter_speed": camera_handler.adjust_shutter_speed(camera, config) + if config["menu_item"] == "AWB": + camera_handler.adjust_awb(camera, config) if config["menu_item"] == "hdr": camera_handler.set_hdr(camera, config) if config["menu_item"] == "video": diff --git a/src/overlay_handler.py b/src/overlay_handler.py index 5551f0ba..5a75b9ba 100644 --- a/src/overlay_handler.py +++ b/src/overlay_handler.py @@ -15,9 +15,14 @@ def display_text(camera, text, config): mode = "Photo Mode" menu_item = config["menu_item"] - shutter_speed_text = compute_shutter_speed_from_us(config["shutter_speed"]) - text = f'{text}\nShutter Speed: {shutter_speed_text}, set: {camera.shutter_speed}' - camera.annotate_text = f'{mode} - exposure mode: {camera.exposure_mode}, iso: {camera.iso}, hdr: {config["hdr"]}\nSelected Menu Item: {config["menu_item"]}\n{text}' + + selected_item = f'Selected Menu Item: {config["menu_item"]}' + camera_settings = f"exposure mode: {camera.exposure_mode}, iso: {camera.iso}\n{selected_item}, awb: {config['awb']}" + + shutter_speed = compute_shutter_speed_from_us(config["shutter_speed"]) + shutter_text = f'Shutter Speed: {shutter_speed}, set: {camera.shutter_speed}' + + camera.annotate_text = f'{mode} - {camera_settings}\nhdr: {config["hdr"]}\n{shutter_text}\n{text}' # https://picamera.readthedocs.io/en/release-1.10/recipes1.html#overlaying-images-on-the-preview def add_overlay(camera, overlay, config): From 0cb0ef38c468f22fa2b0f9b93179f499b08f89a9 Mon Sep 17 00:00:00 2001 From: TRex22 Date: Sat, 1 May 2021 11:26:39 +0200 Subject: [PATCH 2/5] Cleanup codebase based on LGTM recommendations :cop: --- src/camera_handler.py | 38 ++++++++++++++----------------------- src/main.py | 30 +++++++++++------------------ src/overlay_handler.py | 2 +- tools/process_hdr.py | 2 -- tools/process_raw_output.py | 2 -- 5 files changed, 26 insertions(+), 48 deletions(-) diff --git a/src/camera_handler.py b/src/camera_handler.py index 5eb7e12a..3a7781ab 100644 --- a/src/camera_handler.py +++ b/src/camera_handler.py @@ -1,16 +1,9 @@ -import os -import shutil import time import glob -import json from io import BytesIO -from picamerax import PiCamera - -import RPi.GPIO as GPIO from pydng.core import RPICAM2DNG -from pydng.core import RAW2DNG, DNGTags, Tag # Modules import document_handler @@ -116,17 +109,16 @@ def take_hdr_shot(camera, config): width = config["width"] height = config["height"] - dcim_path = config["dcim_path"] - dcim_images_path_raw = config["dcim_images_path_raw"] - dcim_original_images_path = config["dcim_original_images_path"] + # dcim_path = config["dcim_path"] + # dcim_images_path_raw = config["dcim_images_path_raw"] + # dcim_original_images_path = config["dcim_original_images_path"] dcim_hdr_images_path = config["dcim_hdr_images_path"] - dcim_videos_path = config["dcim_videos_path"] - dcim_tmp_path = config["dcim_tmp_path"] + # dcim_videos_path = config["dcim_videos_path"] + # dcim_tmp_path = config["dcim_tmp_path"] camera.resolution = (width, height) start_time = time.time() - available_exposure_compensations = [-25, -20, -15, -10, -5, 0, 5, 10, 15, 20, 25] # TODO # SEE: https://github.com/KEClaytor/pi-hdr-timelapse nimages = 5 #10 #2160 @@ -137,8 +129,6 @@ def take_hdr_shot(camera, config): exp_step = (exposure_max - exposure_min) / (nimages - 1.0) exposure_times = range(exposure_min, exposure_max + 1, int(exp_step)) - filenames = [] - existing_files = glob.glob(f'{dcim_hdr_images_path}/*.{format}') filecount = len(existing_files) frame_count = filecount @@ -172,12 +162,12 @@ def take_single_shot(camera, config): width = config["width"] height = config["height"] - dcim_path = config["dcim_path"] + # dcim_path = config["dcim_path"] dcim_images_path_raw = config["dcim_images_path_raw"] dcim_original_images_path = config["dcim_original_images_path"] - dcim_hdr_images_path = config["dcim_hdr_images_path"] - dcim_videos_path = config["dcim_videos_path"] - dcim_tmp_path = config["dcim_tmp_path"] + # dcim_hdr_images_path = config["dcim_hdr_images_path"] + # dcim_videos_path = config["dcim_videos_path"] + # dcim_tmp_path = config["dcim_tmp_path"] format = config["format"] bayer = config["bayer"] @@ -227,12 +217,12 @@ def trigger_video(camera, config): width = config["width"] height = config["height"] - dcim_path = config["dcim_path"] - dcim_images_path_raw = config["dcim_images_path_raw"] - dcim_original_images_path = config["dcim_original_images_path"] - dcim_hdr_images_path = config["dcim_hdr_images_path"] + # dcim_path = config["dcim_path"] + # dcim_images_path_raw = config["dcim_images_path_raw"] + # dcim_original_images_path = config["dcim_original_images_path"] + # dcim_hdr_images_path = config["dcim_hdr_images_path"] dcim_videos_path = config["dcim_videos_path"] - dcim_tmp_path = config["dcim_tmp_path"] + # dcim_tmp_path = config["dcim_tmp_path"] format = config["video_format"] diff --git a/src/main.py b/src/main.py index 66f474fa..b2460549 100644 --- a/src/main.py +++ b/src/main.py @@ -13,6 +13,8 @@ # 'bgra' - Write the raw image data to a file in 32-bit BGRA format # 'raw' - Deprecated option for raw captures; the format is taken from the deprecated raw_format attribute +# available_exposure_compensations = [-25, -20, -15, -10, -5, 0, 5, 10, 15, 20, 25] + # 8MP pi camera v2.1 # width = 3280 # height = 2464 @@ -21,25 +23,15 @@ # width = 4056 # height = 3040 -VERSION = "0.0.12" +VERSION = "0.0.13" -import os -import shutil import time import glob -import json -from io import BytesIO from picamerax import PiCamera import RPi.GPIO as GPIO -from pydng.core import RPICAM2DNG -from pydng.core import RAW2DNG, DNGTags, Tag - -import numpy as np -from PIL import Image, ImageDraw, ImageFont - # Modules import document_handler import overlay_handler @@ -118,20 +110,20 @@ } } -filetype = config["filetype"] -bpp = config["bpp"] +# filetype = config["filetype"] +# bpp = config["bpp"] # format = config["format"] fps = config["fps"] screen_fps = config["screen_fps"] -dcim_images_path_raw = config["dcim_images_path_raw"] -dcim_original_images_path = config["dcim_original_images_path"] -dcim_hdr_images_path = config["dcim_hdr_images_path"] -dcim_videos_path = config["dcim_videos_path"] -dcim_tmp_path = config["dcim_tmp_path"] +# dcim_images_path_raw = config["dcim_images_path_raw"] +# dcim_original_images_path = config["dcim_original_images_path"] +# dcim_hdr_images_path = config["dcim_hdr_images_path"] +# dcim_videos_path = config["dcim_videos_path"] +# dcim_tmp_path = config["dcim_tmp_path"] -colour_profile_path = config["colour_profile_path"] +# colour_profile_path = config["colour_profile_path"] screen_w = config["screen_w"] screen_h = config["screen_h"] diff --git a/src/overlay_handler.py b/src/overlay_handler.py index 5a75b9ba..67b7ca2e 100644 --- a/src/overlay_handler.py +++ b/src/overlay_handler.py @@ -1,5 +1,5 @@ import numpy as np -from PIL import Image, ImageDraw, ImageFont +from PIL import Image def compute_shutter_speed_from_us(us): if us == 0: diff --git a/tools/process_hdr.py b/tools/process_hdr.py index 1fe8ce63..45579fe6 100644 --- a/tools/process_hdr.py +++ b/tools/process_hdr.py @@ -2,8 +2,6 @@ sys.path.insert(1, '../src/') sys.path.insert(1, 'src/') -import os -import time import glob import cv2 diff --git a/tools/process_raw_output.py b/tools/process_raw_output.py index c5fbe3e9..1e8dfe81 100644 --- a/tools/process_raw_output.py +++ b/tools/process_raw_output.py @@ -6,7 +6,6 @@ sys.path.insert(1, '../src/') sys.path.insert(1, 'src/') -import os import time import glob import re @@ -14,7 +13,6 @@ from io import BytesIO from pydng.core import RPICAM2DNG -from pydng.core import RAW2DNG, DNGTags, Tag # Modules import document_handler From b22933378fd8bb99a89f7a3a1362499d94ff1ca5 Mon Sep 17 00:00:00 2001 From: TRex22 Date: Sat, 1 May 2021 11:33:46 +0200 Subject: [PATCH 3/5] Fix awb mode call :cop: --- src/camera_handler.py | 16 ++++++++-------- src/main.py | 8 ++++---- src/menu_handler.py | 4 ++-- src/overlay_handler.py | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/camera_handler.py b/src/camera_handler.py index 3a7781ab..4864d4fc 100644 --- a/src/camera_handler.py +++ b/src/camera_handler.py @@ -13,7 +13,7 @@ def auto_mode(camera, config): camera.iso = config["default_iso"] camera.exposure_mode = config["default_exposure_mode"] camera.shutter_speed = config["default_shutter_speed"] - camera.awb = config["default_awb"] + camera.awb_mode = config["default_awb_mode"] overlay_handler.display_text(camera, '', config) print(f'auto mode!') @@ -67,17 +67,17 @@ def adjust_shutter_speed(camera, config): overlay_handler.display_text(camera, '', config) print(f'shutter_speed: {config["shutter_speed"]}') -def adjust_awb(camera, config): - idex = config["available_awb"].index(config["awb"]) + 1 +def adjust_awb_mode(camera, config): + idex = config["available_awb_mode"].index(config["awb_mode"]) + 1 - if idex < len(config["available_awb"]): - config["awb"] = config["available_awb"][idex] + if idex < len(config["available_awb_mode"]): + config["awb_mode"] = config["available_awb_mode"][idex] else: - config["awb"] = config["default_awb"] + config["awb_mode"] = config["default_awb_mode"] - camera.awb = config["awb"] + camera.awb_mode = config["awb_mode"] overlay_handler.display_text(camera, '', config) - print(f'awb: {config["awb"]}') + print(f'awb_mode: {config["awb_mode"]}') def set_hdr(camera, config): config["hdr"] = not config["hdr"] diff --git a/src/main.py b/src/main.py index b2460549..77293258 100644 --- a/src/main.py +++ b/src/main.py @@ -91,10 +91,10 @@ "available_shutter_speeds": [0, 100, 500, 1000, 2000, 4000, 8000, 16667, 33333, 66667, 125000, 250000, 500000, 1000000, 2000000, 5000000, 10000000, 15000000, 20000000, 25000000, 30000000, 35000000, 40000000], "shutter_speed": 0, "default_shutter_speed": 0, - "available_awb": ['auto', 'off', 'sunlight', 'cloudy', 'shade', 'tungsten', 'fluorescent', 'incandescent', 'flash', 'horizon'], - "awb": 'auto', - "default_awb": 'auto', # "awb_gains": 0.0 - 8.0 (), - "available_menu_items": ["auto", "exposure_mode", "iso", "shutter_speed", "AWB", "hdr", "video", "resolution", "encoding"], + "available_awb_mode": ['auto', 'off', 'sunlight', 'cloudy', 'shade', 'tungsten', 'fluorescent', 'incandescent', 'flash', 'horizon'], + "awb_mode": 'auto', + "default_awb_mode": 'auto', # "awb_gains": 0.0 - 8.0 (), + "available_menu_items": ["auto", "exposure_mode", "iso", "shutter_speed", "awb_mode", "hdr", "video", "resolution", "encoding"], "menu_item": "auto", "default_menu_item": "auto", "hdr": False, diff --git a/src/menu_handler.py b/src/menu_handler.py index fb4c4bb9..29ebdea6 100644 --- a/src/menu_handler.py +++ b/src/menu_handler.py @@ -21,8 +21,8 @@ def select_option(camera, config): camera_handler.adjust_iso(camera, config) if config["menu_item"] == "shutter_speed": camera_handler.adjust_shutter_speed(camera, config) - if config["menu_item"] == "AWB": - camera_handler.adjust_awb(camera, config) + if config["menu_item"] == "awb_mode": + camera_handler.adjust_awb_mode(camera, config) if config["menu_item"] == "hdr": camera_handler.set_hdr(camera, config) if config["menu_item"] == "video": diff --git a/src/overlay_handler.py b/src/overlay_handler.py index 67b7ca2e..7c88ccde 100644 --- a/src/overlay_handler.py +++ b/src/overlay_handler.py @@ -17,7 +17,7 @@ def display_text(camera, text, config): menu_item = config["menu_item"] selected_item = f'Selected Menu Item: {config["menu_item"]}' - camera_settings = f"exposure mode: {camera.exposure_mode}, iso: {camera.iso}\n{selected_item}, awb: {config['awb']}" + camera_settings = f"exposure mode: {camera.exposure_mode}, iso: {camera.iso}\n{selected_item}, awb mode: {config['awb_mode']}" shutter_speed = compute_shutter_speed_from_us(config["shutter_speed"]) shutter_text = f'Shutter Speed: {shutter_speed}, set: {camera.shutter_speed}' From 4c30b508538920dae658d5046b20671be2fd668d Mon Sep 17 00:00:00 2001 From: TRex22 Date: Sat, 1 May 2021 11:35:56 +0200 Subject: [PATCH 4/5] Cleanup and fix ui :cop: --- src/overlay_handler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/overlay_handler.py b/src/overlay_handler.py index 7c88ccde..1d10cbcf 100644 --- a/src/overlay_handler.py +++ b/src/overlay_handler.py @@ -17,12 +17,12 @@ def display_text(camera, text, config): menu_item = config["menu_item"] selected_item = f'Selected Menu Item: {config["menu_item"]}' - camera_settings = f"exposure mode: {camera.exposure_mode}, iso: {camera.iso}\n{selected_item}, awb mode: {config['awb_mode']}" + camera_settings = f"exposure mode: {camera.exposure_mode}, iso: {camera.iso}, awb mode: {config['awb_mode']}" shutter_speed = compute_shutter_speed_from_us(config["shutter_speed"]) shutter_text = f'Shutter Speed: {shutter_speed}, set: {camera.shutter_speed}' - camera.annotate_text = f'{mode} - {camera_settings}\nhdr: {config["hdr"]}\n{shutter_text}\n{text}' + camera.annotate_text = f'{mode} - {camera_settings}\nhdr: {config["hdr"]}\n{selected_item}\n{shutter_text}\n{text}' # https://picamera.readthedocs.io/en/release-1.10/recipes1.html#overlaying-images-on-the-preview def add_overlay(camera, overlay, config): From 657e9ee06af5b42bddfd999e4476219cd592057c Mon Sep 17 00:00:00 2001 From: TRex22 Date: Sat, 1 May 2021 11:37:00 +0200 Subject: [PATCH 5/5] Cleanup comments :cop: --- src/camera_handler.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/camera_handler.py b/src/camera_handler.py index 4864d4fc..a45af9af 100644 --- a/src/camera_handler.py +++ b/src/camera_handler.py @@ -19,17 +19,6 @@ def auto_mode(camera, config): print(f'auto mode!') def adjust_exposure_mode(camera, config): - # Fix other settings - # Now fix the values - # camera.shutter_speed = 150000 #camera.exposure_speed - # # camera.exposure_mode = 'off' - # # off, auto, night, nightpreview, backlight, spotlight, sports, snow, beach, - # # verylong, fixedfps, antishake, fireworks - # camera.exposure_mode = 'auto' - # g = camera.awb_gains - # camera.awb_mode = 'off' - # camera.awb_gains = g - idex = config["available_exposure_modes"].index(config["exposure_mode"]) + 1 if idex < len(config["available_exposure_modes"]):