Skip to content

Commit d8ef645

Browse files
authored
Add the files provided by guide author
1 parent ececb5e commit d8ef645

8 files changed

Lines changed: 15023 additions & 0 deletions

File tree

PyGamer_Improved_Thermal_Camera/code.py

Lines changed: 498 additions & 0 deletions
Large diffs are not rendered by default.

PyGamer_Improved_Thermal_Camera/fonts/OpenSans-9.bdf

Lines changed: 14362 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# grayscale_spectrum.py
2+
# 2021-05-19 version 1.1
3+
# Copyright 2021 Cedar Grove Studios
4+
# Spectral Index to Grayscale RGB Converter Helper
5+
6+
def map_range(x, in_min, in_max, out_min, out_max):
7+
"""
8+
Maps and constrains an input value from one range of values to another.
9+
(from adafruit_simpleio)
10+
:return: Returns value mapped to new range
11+
:rtype: float
12+
"""
13+
in_range = in_max - in_min
14+
in_delta = x - in_min
15+
if in_range != 0:
16+
mapped = in_delta / in_range
17+
elif in_delta != 0:
18+
mapped = in_delta
19+
else:
20+
mapped = 0.5
21+
mapped *= out_max - out_min
22+
mapped += out_min
23+
if out_min <= out_max:
24+
return max(min(mapped, out_max), out_min)
25+
return min(max(mapped, out_max), out_min)
26+
27+
def index_to_rgb(index=0, gamma=0.8):
28+
"""
29+
Converts a spectral index to a grayscale RGB value. Spectral index in
30+
range of 0.0 to 1.0. Gamma in range of 0.0 to 1.0 (1.0=linear),
31+
default 0.8 for color TFT displays.
32+
:return: Returns a 24-bit RGB value
33+
:rtype: integer
34+
"""
35+
36+
red = grn = blu = map_range(index, 0, 1.0, 0.1, 1.0) ** gamma
37+
38+
return (int(red * 255) << 16) + (int(grn * 255) << 8) + int(blu * 255)
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# iron_spectrum.py
2+
# 2021-05-27 version 1.2
3+
# Copyright 2021 Cedar Grove Studios
4+
# Temperature Index to Iron Pseudocolor Spectrum RGB Converter Helper
5+
6+
def map_range(x, in_min, in_max, out_min, out_max):
7+
"""
8+
Maps and constrains an input value from one range of values to another.
9+
(from adafruit_simpleio)
10+
:return: Returns value mapped to new range
11+
:rtype: float
12+
"""
13+
in_range = in_max - in_min
14+
in_delta = x - in_min
15+
if in_range != 0:
16+
mapped = in_delta / in_range
17+
elif in_delta != 0:
18+
mapped = in_delta
19+
else:
20+
mapped = 0.5
21+
mapped *= out_max - out_min
22+
mapped += out_min
23+
if out_min <= out_max:
24+
return max(min(mapped, out_max), out_min)
25+
return min(max(mapped, out_max), out_min)
26+
27+
def index_to_rgb(index=0, gamma=0.5):
28+
"""
29+
Converts a temperature index to an iron thermographic pseudocolor spectrum
30+
RGB value. Temperature index in range of 0.0 to 1.0. Gamma in range of
31+
0.0 to 1.0 (1.0=linear), default 0.5 for color TFT displays.
32+
:return: Returns a 24-bit RGB value
33+
:rtype: integer
34+
"""
35+
36+
band = index * 600 # an arbitrary spectrum band index; 0 to 600
37+
38+
if band < 70: # dark gray to blue
39+
red = 0.1
40+
grn = 0.1
41+
blu = (0.2 + (0.8 * map_range(band, 0, 70, 0.0, 1.0))) ** gamma
42+
if band >= 70 and band < 200: # blue to violet
43+
red = map_range(band, 70, 200, 0.0, 0.6) ** gamma
44+
grn = 0.0
45+
blu = 1.0 ** gamma
46+
if band >= 200 and band < 300: # violet to red
47+
red = map_range(band, 200, 300, 0.6, 1.0) ** gamma
48+
grn = 0.0
49+
blu = map_range(band, 200, 300, 1.0, 0.0) ** gamma
50+
if band >= 300 and band < 400: # red to orange
51+
red = 1.0 ** gamma
52+
grn = map_range(band, 300, 400, 0.0, 0.5) ** gamma
53+
blu = 0.0
54+
if band >= 400 and band < 500: # orange to yellow
55+
red = 1.0 ** gamma
56+
grn = map_range(band, 400, 500, 0.5, 1.0) ** gamma
57+
blu = 0.0
58+
if band >= 500: # yellow to white
59+
red = 1.0 ** gamma
60+
grn = 1.0 ** gamma
61+
blu = map_range(band, 500, 580, 0.0, 1.0) ** gamma
62+
63+
return (int(red * 255) << 16) + (int(grn * 255) << 8) + int(blu * 255)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# visible_spectrum.py
2+
# 2021-05-27 version 1.2
3+
# Copyright 2021 Cedar Grove Studios
4+
# Spectral Index to Visible (Rainbow) Spectrum RGB Converter Helper
5+
# Based on original 1996 Fortran code by Dan Bruton:
6+
# physics.sfasu.edu/astro/color/spectra.html
7+
8+
def index_to_rgb(index=0, gamma=0.5):
9+
"""
10+
Converts a spectral index to rainbow (visible light wavelength)
11+
spectrum to an RGB value. Spectral index in range of 0.0 to 1.0
12+
(violet --> white). Gamma in range of 0.0 to 1.0 (1.0=linear),
13+
default 0.5 for color TFT displays.
14+
:return: Returns a 24-bit RGB value
15+
:rtype: integer
16+
"""
17+
18+
wl = (index * 320) + 380
19+
20+
if wl < 440:
21+
intensity = 0.1 + (0.9 * (wl - 380) / (440 - 380))
22+
red = ((-1.0 * (wl - 440) / (440 - 380)) * intensity) ** gamma
23+
grn = 0.0
24+
blu = (1.0 * intensity) ** gamma
25+
if wl >= 440 and wl < 490:
26+
red = 0.0
27+
grn = (1.0 * (wl - 440) / (490 - 440)) ** gamma
28+
blu = 1.0 ** gamma
29+
if wl >= 490 and wl < 510:
30+
red = 0.0
31+
grn = 1.0 ** gamma
32+
blu = (-1.0 * (wl - 510) / (510 - 490)) ** gamma
33+
if wl >= 510 and wl < 580:
34+
red = (1.0 * (wl - 510) / (580 - 510)) ** gamma
35+
grn = 1.0 ** gamma
36+
blu = 0.0
37+
if wl >= 580 and wl < 645:
38+
red = 1.0 ** gamma
39+
grn = (-1.0 * (wl - 645) / (645 - 580)) ** gamma
40+
blu = 0.0
41+
if wl >= 645:
42+
intensity = 0.3 + (0.7 * (700 - wl) / (700 - 645))
43+
red = (1.0) ** gamma
44+
grn = (1.0 - intensity) ** gamma
45+
blu = (1.0 - intensity) ** gamma
46+
47+
return (int(red * 255) << 16) + (int(grn * 255) << 8) + int(blu * 255)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# thermal_cam_config.py
2+
# ### Alarm and range default values in Farenheit ###
3+
ALARM_F = 120
4+
MIN_RANGE_F = 60
5+
MAX_RANGE_F = 120
6+
7+
# ### Display characteristics
8+
SELFIE = False # Rear camera view; True for front view
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# thermal_cam_converters.py
2+
3+
def celsius_to_fahrenheit(deg_c=None): # convert C to F; round to 1 degree C
4+
return round(((9 / 5) * deg_c) + 32)
5+
6+
def fahrenheit_to_celsius(deg_f=None): # convert F to C; round to 1 degree F
7+
return round((deg_f - 32) * (5 / 9))
37.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)