Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Hardware_control/PiCameraApp Link.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/chepo92/PiCameraApp/
123 changes: 123 additions & 0 deletions Hardware_control/camera_preview.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Reference: http://picamera.readthedocs.io/en/release-1.10/index.html

from picamera import PiCamera
from time import sleep
from datetime import timedelta
import datetime

# Basic procedure as in point 3.5 Capturing consistent images from readthedocs.io

# 1 Create Camera instance
camera = PiCamera()
# The Pi’s camera has three ports, the still port (for images), the video port (recording), and the preview port.
# Their output is independet so

# 2 Set resolution
camera.resolution=(960,720) # Retrieves or sets the resolution at which image captures, video recordings, and previews will be captured.

# 3 Set frame rate
camera.framerate = 1 # frames/sec, determines the max shutter speed

# 4 Set ISO to the desired value
camera.iso = 500 # Retrieves or sets the apparent ISO setting of the camera.

# 5 Fix the ss
camera.shutter_speed = 300000 #e

# 6 Wait for the automatic gain control to settle (Analog and Digital Gain)
sleep(5)

# Notice: we will skip step 7 as we need the automatic analog and digital gains for live previewing
# as capture and preview use different ports disabling Auto gains now will give a correct captured image but a
# probably dark preview. Uncomment if you are just capturing and not previewing

# 7 Turn off automatic gain (fix AG and DG)
#camera.exposure_mode = 'off'

# 8 Disable AWB gain control
camera.awb_mode = 'off'

# 9 Now fix the Red & Blue gains
camera.awb_gains = [1.0,1.0]


# Advanced camera users:
# -------------------------------------------------------------
# These are other possible parameters to change, depending on experiment:

#camera.analog_gain # Retrieves the current analog gain of the camera.
#camera.awb_gains = [1,1] # Gets or sets the auto-white-balance gains of the camera. [red, blue]. This attribute only has an effect when awb_mode is set to 'off'.
#camera.awb_mode = 'off' # Retrieves or sets the auto-white-balance mode of the camera.
#camera.brightness = 50 # Retrieves or sets the brightness setting of the camera. [0,100]
#camera.color_effects=None # Retrieves or sets the current color effect applied by the camera.
#camera.contrast = 0 # Retrieves or sets the contrast setting of the camera. Useful to take reduce the background
#camera.digital_gain # Retrieves the current digital gain of the camera.
#camera.exposure_compensation=0 # Retrieves or sets the exposure compensation level of the camera.
#camera.exposure_mode = 'off' # Retrieves or sets the exposure mode of the camera.
#camera.exposure_speed # Retrieves the current shutter speed of the camera.
#camera.framerate = 0.01 # Retrieves or sets the framerate at which video-port based image captures, video recordings, and previews will run.
#camera.image_denoise # Retrieves or sets whether denoise will be applied to image captures. Default true
#camera.image_effect='none'
#camera.image_effect_params
#camera.meter_mode
#camera.rotation = 90 # Retrieves or sets the current rotation of the camera’s image.
#camera.saturation = 0 # Retrieves or sets the saturation setting of the camera.
#camera.sensor_mode # Retrieves or sets the input mode of the camera’s sensor. setting this property does nothing unless the camera has been initialized with a sensor mode other than 0.
#camera.sharpness = 0 # Retrieves or sets the sharpness setting of the camera. [-100, 100]
#camera.shutter_speed = 500000 # Retrieves or sets the shutter speed of the camera in microseconds.

# alpha window transparency
#alpha =0
#camera.start_preview(alpha =200)
# -------------------------------------------------------------


# 10 Start preview
camera.start_preview()

# Wait for "Intro" input
raw_input('Wait for the preview window, then press enter to take photo and close preview: ')

# 7 Turn off automatic gain (fix AG and DG)
camera.exposure_mode = 'off'

# 11 Take Picture
# Any attempt to capture an image without using the video port optiob will (temporarily)
# select the 2592x1944 mode while the capture is performed (this is what causes
# the flicker you sometimes see when a preview is running while a still image is captured).
datestr = datetime.datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
fname = "preview_" + datestr + ".png"
camera.capture(fname, 'png') # use_video_port defaults to False which means that the camera’s image port is used. This port is slow but produces better quality pictures.

# Query shutter speed value
e = camera.exposure_speed
print('Shutter Speed: ' + str(e))

# Query AWB gains
g = camera.awb_gains
print('AWB gains ' + str(g))

# Query iso
i = camera.iso
print('ISO ' + str(i))

# Query A gain
a=camera.analog_gain
print('A Gain ' + str(a))

# Query D gains
d=camera.digital_gain
print('D Gain ' + str(d))

b=camera.brightness
print('brightness ' + str(b))

c=camera.contrast
print('contrast ' + str(c))

camera.stop_preview()

camera.close()
6 changes: 6 additions & 0 deletions Hardware_control/readEXIF.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from PIL import Image
from PIL.ExifTags import TAGS
img = Image.open('s.jpg')
exif_data = img._getexif()
for tag, value in exif_data.items():
print TAGS.get(tag, tag), value
112 changes: 90 additions & 22 deletions Hardware_control/timelapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
if len(sys.argv)==5:
folder = str(sys.argv[1]) # e.g. Timelapse
filename = str(sys.argv[2]) # e.g. im_exp1
interval = int(sys.argv[3]) # wait time in seconds e.g. 1800
steps = int(sys.argv[4]) # number of images e.g 200
interval = int(sys.argv[3]) # wait time in seconds e.g. 1800
steps = int(sys.argv[4]) # number of images e.g 200
else:
print ("Required parameters: folder name, filename, interval (secs), number of steps.")
sys.exit()
Expand All @@ -30,31 +30,99 @@
# make the folder if it doesn't exist
if os.path.exists(folder) == False:
os.mkdir(folder)

# Minimal camera settings
camera.resolution=(960,720)
camera.ISO=400
camera.framerate = 1 # frames/sec, determines the max shutter speed
camera.shutter_speed = 200000 # exposure time in microsecs
camera.exposure_mode = 'off' #'fixedfps'
camera.awb_gains = [1,1]

#Variables
#hRes = 960
#vRes = 720
fr = 1
iso = 500
ss= 300000
redG = 1.0
blueG = 1.0
b= 50
c= 0

# Basic procedure as in point 3.5 Capturing consistent images from readthedocs.io

# 1 Create Camera instance
camera = PiCamera()
# The Pi’s camera has three ports, the still port (for images), the video port (recording), and the preview port.
# Their output is independet so

# 2 Set resolution
camera.resolution=(960,720) # Retrieves or sets the resolution at which image captures, video recordings, and previews will be captured.

# 3 Set frame rate
camera.framerate = fr # frames/sec, determines the max shutter speed

# 4 Set ISO to the desired value
camera.iso = iso # Retrieves or sets the apparent ISO setting of the camera.

# 5 Fix the ss
camera.shutter_speed = ss #e

# 6 Wait for the automatic gain control to settle (Analog and Digital Gain)
sleep(5)

# Notice: we will skip step 7 as we need the automatic analog and digital gains for live previewing
# as capture and preview use different ports disabling Auto gains now will give a correct captured image but a
# probably dark preview. Uncomment if you are just capturing and not previewing

# 7 Turn off automatic gain (fix AG and DG)
# camera.exposure_mode = 'off'

# 8 Disable AWB gain control
camera.awb_mode = 'off'

# 9 Now fix the Red & Blue gains
camera.awb_gains = [redG,blueG]


# Advanced camera users:
# -------------------------------------------------------------
# These are other possible parameters to change, depending on experiment:
#camera.analog_gain = 1
#camera.digital_gain=1
#camera.brightness = 50
#camera.sharpness = 0
#camera.contrast = 0 # useful to take reduce the background
#camera.saturation = 0
#camera.exposure_compensation=0

#camera.analog_gain # Retrieves the current analog gain of the camera.
#camera.awb_gains = [1,1] # Gets or sets the auto-white-balance gains of the camera. [red, blue]. This attribute only has an effect when awb_mode is set to 'off'.
#camera.awb_mode = 'off' # Retrieves or sets the auto-white-balance mode of the camera.
#camera.brightness = 50 # Retrieves or sets the brightness setting of the camera. [0,100], Default 50
#camera.color_effects=None # Retrieves or sets the current color effect applied by the camera.
#camera.contrast = 0 # Retrieves or sets the contrast setting of the camera. Useful to take reduce the background [0,100]. Default 0
#camera.digital_gain # Retrieves the current digital gain of the camera.
#camera.exposure_compensation=0 # Retrieves or sets the exposure compensation level of the camera.
#camera.exposure_mode = 'off' # Retrieves or sets the exposure mode of the camera.
#camera.exposure_speed # Retrieves the current shutter speed of the camera.
#camera.framerate = 0.01 # Retrieves or sets the framerate at which video-port based image captures, video recordings, and previews will run.
#camera.image_denoise # Retrieves or sets whether denoise will be applied to image captures. Default true
#camera.image_effect='none'
#camera.color_effects=None
#camera.framerate = 0.01
#camera.exposure_speed
#camera.image_effect_params
#camera.meter_mode
#camera.rotation = 90 # Retrieves or sets the current rotation of the camera’s image.
#camera.saturation = 0 # Retrieves or sets the saturation setting of the camera.
#camera.sensor_mode # Retrieves or sets the input mode of the camera’s sensor. setting this property does nothing unless the camera has been initialized with a sensor mode other than 0.
#camera.sharpness = 0 # Retrieves or sets the sharpness setting of the camera. [-100, 100]
#camera.shutter_speed = 500000 # Retrieves or sets the shutter speed of the camera in microseconds.

# alpha window transparency
# alpha =0
# camera.start_preview(alpha =200)
# -------------------------------------------------------------

# 10 Start preview
camera.start_preview()

# Wait for "Intro" input
raw_input('Wait for the preview window, then press enter to take photo and close preview: ')

# 7 Turn off automatic gain (fix AG and DG)
camera.exposure_mode = 'off'

#12 Stop preview
camera.stop_preview()

# -------------------------------------------------------------


# Save this file with the data (to record settings etc.)
scriptpath = os.path.dirname(os.path.realpath(__file__))
copyfile(os.path.join(scriptpath, sys.argv[0]), os.path.join(folder, 'script.py'))
Expand All @@ -70,8 +138,8 @@
GPIO.output(29,GPIO.HIGH)

datestr = datetime.datetime.now().strftime("%Y-%m-%d-%H_%M_%S")
fname = os.path.join(folder, datestr + "_" + filename + "_%04d.jpg"%(i))
camera.capture(fname)
fname = os.path.join(folder, datestr + "_" + filename + "_%04d.png"%(i))
camera.capture(fname,'png')

#turn the LEDs off
GPIO.output(29,GPIO.LOW)
Expand Down
9 changes: 9 additions & 0 deletions sh.exe.stackdump
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Exception: STATUS_STACK_OVERFLOW at rip=00076E0BF37
rax=0000000000001250 rbx=00000000FFFFAE70 rcx=0000000000000000
rdx=0000000180010018 rsi=00000000FFFFAE78 rdi=000000018028E980
r8 =00000000003B4962 r9 =000000018028E980 r10=00000000FFFF9000
r11=00000000FFE031F0 r12=0000000000000420 r13=00000000FFFFAD50
r14=000000018022F490 r15=00000000FFFFACF0
rbp=000000000000026C rsp=00000000FFFFABC8
program=C:\Users\Axel\AppData\Local\GitHubDesktop\app-1.2.6\resources\app\git\usr\bin\sh.exe, pid 7864, thread
cs=0033 ds=002B es=002B fs=0053 gs=002B ss=002B