Skip to content

Commit

Permalink
Merge pull request #5 from TRex22/development
Browse files Browse the repository at this point in the history
  • Loading branch information
TRex22 authored May 1, 2021
2 parents ac4c41b + 657e9ee commit 47e4827
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 66 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
62 changes: 27 additions & 35 deletions src/camera_handler.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,22 +13,12 @@ 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_mode = config["default_awb_mode"]

overlay_handler.display_text(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"]):
Expand Down Expand Up @@ -73,6 +56,18 @@ def adjust_shutter_speed(camera, config):
overlay_handler.display_text(camera, '', config)
print(f'shutter_speed: {config["shutter_speed"]}')

def adjust_awb_mode(camera, config):
idex = config["available_awb_mode"].index(config["awb_mode"]) + 1

if idex < len(config["available_awb_mode"]):
config["awb_mode"] = config["available_awb_mode"][idex]
else:
config["awb_mode"] = config["default_awb_mode"]

camera.awb_mode = config["awb_mode"]
overlay_handler.display_text(camera, '', config)
print(f'awb_mode: {config["awb_mode"]}')

def set_hdr(camera, config):
config["hdr"] = not config["hdr"]
overlay_handler.display_text(camera, '', config)
Expand Down Expand Up @@ -103,17 +98,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
Expand All @@ -124,8 +118,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
Expand Down Expand Up @@ -159,12 +151,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"]
Expand Down Expand Up @@ -214,12 +206,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"]

Expand Down
35 changes: 15 additions & 20 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -99,7 +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_menu_items": ["auto", "exposure_mode", "iso", "shutter_speed", "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,
Expand All @@ -115,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"]
Expand Down
2 changes: 2 additions & 0 deletions src/menu_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_mode":
camera_handler.adjust_awb_mode(camera, config)
if config["menu_item"] == "hdr":
camera_handler.set_hdr(camera, config)
if config["menu_item"] == "video":
Expand Down
13 changes: 9 additions & 4 deletions src/overlay_handler.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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}, 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{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):
Expand Down
2 changes: 0 additions & 2 deletions tools/process_hdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
sys.path.insert(1, '../src/')
sys.path.insert(1, 'src/')

import os
import time
import glob

import cv2
Expand Down
2 changes: 0 additions & 2 deletions tools/process_raw_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
sys.path.insert(1, '../src/')
sys.path.insert(1, 'src/')

import os
import time
import glob
import re

from io import BytesIO

from pydng.core import RPICAM2DNG
from pydng.core import RAW2DNG, DNGTags, Tag

# Modules
import document_handler
Expand Down

0 comments on commit 47e4827

Please sign in to comment.