In a certain production, I decided to incorporate non-contact temperature measurement into the system, so I implemented it using Raspberry Pi + thermo sensor. It is not a handheld image, but a stationary image.
PC OS: macOS Catalina v10.15 Thermosensor: https://www.switch-science.com/catalog/3395/ Raspberry Pi 3B +: https://www.switch-science.com/catalog/3920/
Overview of thermosensor
The temperature measurement range for each element is 0 ° C to 80 ° C. The measurement area is a square pyramid in front of the sensor (about 60 degrees vertically and horizontally), and a two-dimensional image obtained by dividing this area into 8x8 pixels can be obtained.
The explanation of Raspberry Pi setup and connection is omitted. It is assumed that the terminal can be used by SSH or display connection.
Nowadays, it seems that there is a tool for installing the OS on Raspberry Pi, so I think you should refer to the following article.
https://www.itmedia.co.jp/news/articles/2006/05/news031.html
terminal
sudo raspi-config
The CUI selection screen will appear, so It can be enabled with I2C-> enabled.
Use a breadboard. Reference
After wiring, execute the command to check if the connection is established.
terminal
i2cdetect -y 1
If there is 68, it is recognized correctly.
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- 68 -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Installation of required modules
sudo pip3 install adafruit-circuitpython-amg88xx
Temperature measurement program
import time
import busio
import board
import adafruit_amg88xx
i2c_bus = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_amg88xx.AMG88XX(i2c_bus, addr=0x68)
time.sleep(0.5) #If you do not put a sleep, sensor.I can't get pixels
print(sensor.pixels)
When executed, a two-dimensional array will be returned.
terminal
sudo python3 test.py
[[23.5, 23.5, 24.25, 23.75, 23.25, 24.5, 24.25, 23.25], [23.0, 24.0, 23.5, 24.0, 23.75, 24.25, 24.5, 24.25], [23.75, 23.25, 23.75, 24.0, 23.75, 24.5, 24.5, 24.75], [23.25, 23.25, 23.25, 24.0, 23.5, 24.25, 24.5, 25.75], [23.5, 23.75, 23.75, 24.0, 23.5, 24.25, 24.0, 24.0], [23.75, 23.25, 24.25, 23.5, 23.75, 23.25, 23.75, 24.0], [23.25, 23.75, 23.5, 24.25, 23.75, 23.5, 24.0, 24.0], [23.5, 23.0, 24.0, 23.75, 23.25, 23.25, 24.75, 23.75]]
If you plot it in an easy-to-understand manner ...
import time
import busio
import board
import adafruit_amg88xx
import matplotlib.pyplot as plt
i2c_bus = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_amg88xx.AMG88XX(i2c_bus, addr=0x68)
time.sleep(0.5)
fig = plt.imshow(sensor.pixels, cmap="inferno")
plt.colorbar()
plt.savefig("plot.png ")
It's a face. You can get it like that.
Since it is necessary to measure the temperature around the forehead, it is necessary to have the user fix the position of the face when measuring the temperature in a stationary state. Furthermore, ideally, it is good for UX when the temperature measurement starts when the face is aligned in place.
In order to realize these, I prepared a camera module separately and measured the temperature by using the detection that the face was in the specified position as a trigger. Ask the user to meet face to face by relying on the camera and frame shown on the display. Of course, when implementing this, it is necessary to fix the position of the camera and the relative position of the thermosensor.
Below is a sample program. Face detection used OpenCV. (The actual code is modified for the sample, and the operation has not been confirmed.)
import picamera
import picamera.array
import time
import cv2
import busio
import board
import adafruit_amg88xx
#Cascade file uses the one that is distributed
CascadeFile = "./haarcascade_frontalface_default.xml"
with picamera.PiCamera() as camera:
#Camera settings
camera.resolution = (400, 400)
camera.rotation = 180
camera.start_preview()
time.sleep(2)
with picamera.array.PiRGBArray(camera) as stream:
while True:
#Of the camera(50,50)From(350,350)Since the minimum size for face recognition and face recognition is 250x250, the recognition position and size can be narrowed down.
camera.capture(stream, 'bgr', use_video_port=True)
gray = cv2.cvtColor(stream.array[50:350, 50:350], cv2.COLOR_BGR2GRAY)
cascade = cv2.CascadeClassifier(CascadeFile)
face_list = cascade.detectMultiScale(gray, minSize=(250, 250), minNeighbors=3)
if len(face_list) > 0:
x, y, w, h = face_list[0]:
temps = []
i2c_bus = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_amg88xx.AMG88XX(i2c_bus, addr=0x68)
#Temperature measurement 5 times
for i in range(5):
time.sleep(0.3)
_max = 0
for j in sensor.pixels[2:6]:
for k in j[3:5]:
_max = max(_max, k) #Handle the maximum value in the range
temps.append(_max + 5) #Filling the gap between surface temperature and body temperature
print(round(sum(sorted(temps)[1:4]) / 3, 1)) #Sort the temperature measurement results and output the average of the three
break
stream.seek(0)
stream.truncate()
camera.stop_preview()
There may be room for improvement in this part. (Determine this value based on the temperature, etc.)
temps.append(_max + 5) #Filling the gap between surface temperature and body temperature
It's hard to explain this code in detail, so check out around OpenCV`` PiCamera
for more information.
It is a rough implementation by students in production, so please do not refer to it too much if certainty is required.
Thank you very much.
Recommended Posts