Thermal imaging face following thermometer based on Stm32F1 and Openmv


Summary

  Design and implement a human body tracking temperature detection system based on STM32, combined with circuit design requirements and economy, real-time, select STM32F103C8T6 microcontroller as the main control chip and AMG8833 thermal imaging temperature sensor to realize the detection of human body temperature, based on Openmv Image processing realizes face and forehead tracking, realizes automatic human body non-contact body temperature measurement, real-time display on the Oled LCD screen, and activates an audible and visual alarm when the temperature exceeds a predetermined temperature. This article introduces the block diagram of the system's software and hardware architecture, the schematic diagram of the hardware circuit design and the main external modules.

1. Program overview

  According to the functional requirements of the system design, the design of this automatic human body tracking temperature measurement system is realized by circuit design combined with a single-chip embedded system. The design system consists of seven modules , including main control circuit module, temperature measurement module, sound and light alarm module, display module, pan/tilt module, image acquisition and processing module, and keyboard module (the power module is added to the PCB and hardware design).

2. Specific plan design

1. Module selection

Main control chip: STM32F103C8T6

Temperature measurement module: AMG8833

Image processing module: Openmv

  The OpenMV used is an open source, low-cost, and powerful machine vision module. Integrated OV7725 camera chip, internal image noise reduction and stabilization module, on the small hardware module, the core machine vision algorithm is efficiently implemented in C language, equipped with MicroPython interpreter, which allows you to use Python to program on embedded , Built-in image processing algorithm and network training model, integrated hardware to facilitate direct programming operation, higher speed and efficiency [3], can meet the real-time requirements of the system.

2. System block diagram

2.1 System architecture

  Based on the automatic temperature measurement system designed by STM32F103RCT6, the main control circuit is composed of STM32 microprocessor and its peripheral circuits. It is the core part of the system and mainly completes data transmission and processing. The whole system consists of seven modules, including the single-chip microcomputer main control module, temperature measurement module, sound and light alarm module, display module, keyboard module, pan-tilt module, and image acquisition and processing module. When someone enters, the temperature measurement circuit is started, the temperature measurement sensor is moved synchronously to track the human head, and the temperature is measured by the temperature chip AMG8833, which can accurately measure the temperature in a short time. The microcontroller drives the LCD module to display the current measured temperature. The temperature is greater than 37.8 ℃ to drive the alarm circuit. The whole system modules are divided into seven modules, including the single-chip microcomputer main control module, temperature measurement module, sound and light alarm module, display module, keyboard module, pan/tilt module, and image acquisition and processing module.
System Block Diagram

2.2 System software design process

  The main software design program is that the pan/tilt is in a cyclic scanning state. The OpenMV integrated camera mounted on the pan/tilt can obtain real-time image information and return it to the OpenMV main chip. After image noise reduction and filtering, it is converted into a grayscale image, and effective features are extracted, etc. Preprocessing operation, import the network training model for target feature recognition, when a pedestrian is detected, import the face key point feature library synchronously, use the built-in Haar Cascade cascade feature detector of Openmv to realize the face feature point detection, and obtain the forehead The coordinate information is returned to the single-chip microcomputer, the serial port transmission information is detected, the single-chip computer enters the serial port to interrupt, calculates the update information of the PTZ, updates the PTZ in real time, and the temperature sensor mounted on the PTZ obtains the temperature of the forehead. When the temperature exceeds 37.8°C, it starts. Audible alarm. The system can be reset through the keyboard module.

Insert picture description here
Stm32 part of the source code
Openmv detects faces

import sensor, image, time

from pid import PID
from pyb import Servo

pan_servo=Servo(1)
tilt_servo=Servo(2)

red_threshold  = (13, 49, 18, 61, 6, 47)

pan_pid = PID(p=0.07, i=0, imax=90) #脱机运行或者禁用图像传输,使用这个PID
tilt_pid = PID(p=0.05, i=0, imax=90) #脱机运行或者禁用图像传输,使用这个PID
#pan_pid = PID(p=0.1, i=0, imax=90)#在线调试使用这个PID
#tilt_pid = PID(p=0.1, i=0, imax=90)#在线调试使用这个PID

sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # use RGB565.
sensor.set_framesize(sensor.QVGA) # use QQVGA for speed.
sensor.set_vflip(True)
sensor.skip_frames(10) # Let new settings take affect.
sensor.set_auto_whitebal(False) # turn this off.
clock = time.clock() # Tracks FPS.
face_cascade = image.HaarCascade("frontalface", stages=25)

def find_max(blobs):
    max_size=0
    for blob in blobs:
        if blob[2]*blob[3] > max_size:
            max_blob=blob
            max_size = blob[2]*blob[3]
    return max_blob


while(True):
    clock.tick() # Track elapsed milliseconds between snapshots().
    img = sensor.snapshot() # Take a picture and return the image.

    faces = img.find_features(face_cascade, threshold=0.5, scale=1.25)
    if faces:
        face = find_max(faces)
        cx = int(face[0]+face[2]/2)
        cy = int(face[1]+face[3]/2)
        pan_error = cx-img.width()/2
        tilt_error = cy-img.height()/2

        print("pan_error: ", pan_error)

        img.draw_rectangle(face) # rect
        img.draw_cross(cx, cy) # cx, cy

        pan_output=pan_pid.get_pid(pan_error,1)
        tilt_output=tilt_pid.get_pid(tilt_error,1)
        print("pan_output",pan_output)
        pan_servo.angle(pan_servo.angle()+pan_output)
        tilt_servo.angle(tilt_servo.angle()+tilt_output)

Openmv control gimbal

from pyb import millis
from math import pi, isnan

class PID:
    _kp = _ki = _kd = _integrator = _imax = 0
    _last_error = _last_derivative = _last_t = 0
    _RC = 1/(2 * pi * 20)
    def __init__(self, p=0, i=0, d=0, imax=0):
        self._kp = float(p)
        self._ki = float(i)
        self._kd = float(d)
        self._imax = abs(imax)
        self._last_derivative = float('nan')

    def get_pid(self, error, scaler):
        tnow = millis()
        dt = tnow - self._last_t
        output = 0
        if self._last_t == 0 or dt > 1000:
            dt = 0
            self.reset_I()
        self._last_t = tnow
        delta_time = float(dt) / float(1000)
        output += error * self._kp
        if abs(self._kd) > 0 and dt > 0:
            if isnan(self._last_derivative):
                derivative = 0
                self._last_derivative = 0
            else:
                derivative = (error - self._last_error) / delta_time
            derivative = self._last_derivative + \
                                     ((delta_time / (self._RC + delta_time)) * \
                                        (derivative - self._last_derivative))
            self._last_error = error
            self._last_derivative = derivative
            output += self._kd * derivative
        output *= scaler
        if abs(self._ki) > 0 and dt > 0:
            self._integrator += (error * self._ki) * scaler * delta_time
            if self._integrator < -self._imax: self._integrator = -self._imax
            elif self._integrator > self._imax: self._integrator = self._imax
            output += self._integrator
        return output
    def reset_I(self):
        self._integrator = 0
        self._last_derivative = float('nan')

Guess you like

Origin blog.csdn.net/weixin_45336082/article/details/115030061