I'm new to the forum and I certainly don't know the rules. But I have a question I want to determine the temperature of the face with a Raspberry 4 and two cameras one normal, the other thermal (MLX90640). My question is how can I determine the temperature of the face with the thermal camera every time the normal camera detects a face? I wrote a code but it detects the temperature of the environment not that of the face. I tried a correction but I have an error message that I would post. Thank you
import cv2,io,imutils
import numpy as np
from imutils.video import VideoStream
import time
import board
import busio
import adafruit_mlx90640
import random
import math
PRINT_TEMPERATURES = True
i2c = busio.I2C(board.SCL, board.SDA, frequency=800000)
mlx = adafruit_mlx90640.MLX90640(i2c)
print("MLX addr detected on I2C")
print([hex(i) for i in mlx.serial_number])
frame = [0]*768
mlx.refresh_rate = adafruit_mlx90640.RefreshRate.REFRESH_8_HZ
print("Starting Camera...........")
detector= cv2.CascadeClassifier('/home/pi/opencv/data/haarcascades/haarcascade_frontalface_alt.xml')
cap = cv2.VideoCapture(0)
max_t=0
height = cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 24)
width = cap.set(cv2.CAP_PROP_FRAME_WIDTH, 32)
fps = cap.set(cv2.CAP_PROP_FPS, 10)
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
while(True):
ret,img = cap.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = detector.detectMultiScale(gray, 1.3, 5)
mlx.getFrame(frame)
for h in range(24):
for w in range(32):
for (x,y,w,h) in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
roi = frame [y:y+h,x:x+w]
max_t = max(roi)
min_t = int (min(frame))
roi_gray = roi.astype(np.uint8)
roi = cv2.applyColorMap(roi, cv2.COLORMAP_JET)
text = "Min : "+ str(min_t) + "C Max :" + str(max_t) + "C"
org = (10, 40)
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(roi, text, org, font, 1, (255, 255, 255), 2, cv2.LINE_AA)
cv2.imshow('Screen1',roi)
if PRINT_TEMPERATURES:
print("%d",max_t)
text = "occupe"
cv2.imshow('Screen',img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
Traceback (most recent call last):
File "/home/pi/Downloads/ta.py", line 39, in <module>
roi = frame [y:y+h,x:x+w]
TypeError: list indices must be integers or slices, not tuple