├── .gitignore
├── LICENSE
├── README.md
├── exposurebracket.py
└── run_hdrcapture.bsh
/.gitignore:
--------------------------------------------------------------------------------
1 | picam.rsp
2 | 2019*
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 Andy McNeil
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # piHDR
2 | Scripts for capturing and processing HDR images on a raspberry pi with a raspberrypi compatable camera module
3 |
4 |
5 |
6 | ### How to use:
7 | execute `./run_hdrcapture.bsh` to capture exposure bracketed jpgs, create an HDR image, calculate glare metrics, crate a falsecolor image, and create a tone-mapped image.
8 |
9 |
10 | ### Using cron to schedule regular captures.
11 | Use `crontab -e` to edit crontab file
12 |
13 | To capture an hdr image every 5 minutes between 8AM and 7PM on weekdays, add this to the file crontab file:
14 | ```
15 | */5 8-19 * * 1-5 bash /home/pi/piHDR/run_hdrcapture.bsh
16 | ```
17 | Make sure the pi is set to auto login to the user with the crontab file.
18 |
19 |
20 |
21 | ## Setting up dependencies
22 | Dependencies include:
23 | * imagemagic ```sudo apt-get install imagemagick```
24 | * Radiance (pfilt, evalglare, pcond, falsecolor, ra_tiff http://www.radiance-online.org/)
25 | * genHDR (http://www.anyhere.com/)
26 | * python
27 | * picamera
28 |
29 | ### Compiling Radiance for Raspberry Pi
30 | ```
31 | sudo apt-get install tcsh
32 | sudo apt-get install libx11-dev
33 | wget --no-check-certificate http://www.radiance-online.org/software/snapshots/radiance-HEAD.tgz
34 | wget --no-check-certificate http://www.radiance-online.org/download-install/radiance-source-code/latest-release/rad5R0supp.tar.gz
35 | tar -xf radiance-HEAD.tgz
36 | tar -xf rad5R0supp.tar.gz
37 | cd ray
38 | sudo ./makeall install
39 | ```
40 |
41 | ### Installing genHDR
42 | ```
43 | wget http://www.anyhere.com/gward/pickup/hdrgen_AMDRaspian.tar.gz
44 | tar -xf hdrgen_AMDRaspian.tar.gz
45 | sudo mv hdrgen /usr/local/bin/.
46 | sudo mv hdrcvt /usr/local/bin/.
47 | ```
48 |
49 | ### Enabling the camera module (added resolution for PiCamera v2 requires 256MB GPU RAM)
50 | ```
51 | sudo raspi-config
52 | select "7 Advanced Options"
53 | select "A3 Memory Split"
54 | Enter "256"
55 | Select ""
56 | Select ""
57 | Select "" in answer to "Would you like to reboot now?"
58 |
59 | sudo reboot
60 | ```
61 |
62 | ### Enabling the camera module
63 | ```
64 | sudo raspi-config
65 | select "5 Interfacing Options"
66 | select "P1 Camera"
67 | select "Yes"
68 |
69 | sudo reboot
70 | ```
71 |
72 | ### Disable Camera LED ###
73 | The red LED on the camera module can affect your images, especially if you use clip on lenses. The instructions to disable the LED below come from this website: http://www.raspberrypi-spy.co.uk/2013/05/how-to-disable-the-red-led-on-the-pi-camera-module/
74 | ```
75 | sudo nano /boot/config.txt
76 | ```
77 | add the following:
78 | ```
79 | disable_camera_led=1
80 | ```
81 |
82 | ### Watchits: ###
83 | * Make sure you have the python library picamera (you should)
84 | * Make sure that you have the camera installed correctly and on the correct port
85 | https://www.youtube.com/watch?time_continue=152&v=GImeVqHQzsE
86 | * Set the field of view variables in run_hdrcapture.bsh for your camera + lens combo
87 | * Make sure the path to piHDR in run_hdrcapture.bsh is valid.
88 |
89 |
90 |
--------------------------------------------------------------------------------
/exposurebracket.py:
--------------------------------------------------------------------------------
1 | import picamera
2 | from time import sleep
3 | from fractions import Fraction
4 |
5 | # This script captures exposures with varying shutter time.
6 | # The frame rate needs to be longer than the exposure or it won't work.
7 | # The capture takes as long as the frame rate, so reducing the frame rate saves time for quick exposures.
8 |
9 | with picamera.PiCamera() as camera:
10 | # detect camera version so that it resolution can be set
11 | if (camera.revision).upper() == "IMX219":
12 | try:
13 | camera.resolution = (3280,2464)
14 | except:
15 | print("Review readme for change in memory split to get full support for Camera v2")
16 | print("Resolution kept at 2592x1944")
17 | camera.resolution = (2592,1944)
18 | else:
19 | #(camera.revision).upper() == "IMX219":
20 | camera.resolution = (2592,1944)
21 | camera.framerate = Fraction(1, 2)
22 | camera.iso = 100
23 | camera.exposure_mode = 'off'
24 | camera.awb_mode = 'off'
25 | camera.awb_gains = (1.8,1.8)
26 | #0.8s exposure
27 | camera.framerate = 1
28 | camera.shutter_speed = 800000
29 | camera.capture('ldr_01.jpg')
30 | #0.2s exposure
31 | camera.framerate = 5
32 | camera.shutter_speed = 200000
33 | camera.capture('ldr_02.jpg')
34 | #0.05s exposure
35 | camera.framerate = 20
36 | camera.shutter_speed = 50000
37 | camera.capture('ldr_03.jpg')
38 | #0.0125s exposure
39 | camera.framerate = 30
40 | camera.shutter_speed = 12500
41 | camera.capture('ldr_04.jpg')
42 | #0.003125s exposure
43 | camera.shutter_speed = 3125
44 | camera.capture('ldr_05.jpg')
45 | #0.0008s exposure
46 | camera.shutter_speed = 800
47 | camera.capture('ldr_06.jpg')
48 |
--------------------------------------------------------------------------------
/run_hdrcapture.bsh:
--------------------------------------------------------------------------------
1 | #! /bin/bash
2 |
3 | ## camera field of view (for evalglare)
4 | vv=97.2
5 | vh=190
6 |
7 | ## set the path variable, particularly useful if you're using cron to schedule captures
8 | export PATH=$PATH:/usr/local/bin/:/home/pi/piHDR
9 |
10 | # move to the directory
11 | cd /home/pi/piHDR
12 |
13 | # create a directory with date and time. The $dir variable is also used for filenames
14 | dir=`date +"%Y%m%d_%H%M"`
15 | mkdir $dir
16 | cd $dir
17 |
18 | # call the python script to control the camera
19 | python ../exposurebracket.py
20 |
21 | # create the HDR image (get hdrgen from anyhere.com)
22 | hdrgen -a -r ../picam.rsp -o ${dir}.hdr ldr_0?.jpg
23 |
24 | # make a smaller image for quicker analysis
25 | pfilt -1 -e 1 -x 800 -y 600 ${dir}.hdr > ${dir}.pic
26 | # if you're interested in a full resolution HDR you may want to use the line below
27 | # and comment the line above with a "#", FULL RESOLUTION CAN TAKE SOME TIME TO CREATE
28 | # pfilt -1 -e 1 ${dir}.hdr > ${dir}.pic
29 |
30 | # calculate glare metrics
31 | evalglare -vta -vv $vv -vh $vh ${dir}.pic > glare.txt &
32 |
33 | #create a falsecolor image & convert to tif
34 | falsecolor -s 20000 -log 3 -ip ${dir}.pic | ra_tiff -z - ${dir}_f.tif &
35 |
36 | #create a tone mapped luminance photo
37 | pcond ${dir}.pic | ra_tiff -z - ${dir}.tif &
38 |
39 | #create a JPG of the tiff for use as well
40 | #note: this requires the installition of imageMagick
41 | convert ${dir}.tif ${dir}.jpg
42 |
43 | # wait for the three background analysis processes above to complete.
44 | wait
45 |
46 |
--------------------------------------------------------------------------------