表面温度[关闭]

问题描述 投票:0回答:1

希望您一切都好。我的程序有问题,我想显示人脸的温度,在那里我可以检测到人脸,但它需要的环境温度超出了我想要的人脸温度。别客气。那么,您可以使用我的代码帮助我检测面部温度吗?我使用MLX90640

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 = np.zeros(img.shape[: 2], np.uint8)
roi = cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
max_t = int(max(frame))
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()
opencv temperature
1个回答
0
投票

[您正在用摄像机检测面部,并且正在使用热像仪获取温度。据我所知,adafruit_mlx90640没有嵌入式摄像机。因此,您应该做的第一件事就是使转换从摄像机图像坐标转换为热图像坐标(应该是齐次矩阵)。这种转换为您提供了热像仪中视频像素的位置。

一旦有了这个,就将它应用到检测到的面部。因此,您在热图像空间中获得了脸部坐标。

如果使用热图像检测人脸,则要简单得多。您不需要转换面部坐标。

然后为每个脸部,在热图像中获取ROI,并计算该ROI中的最高温度。

要获取子matmat并计算其最大值,可以使用:

for (x, y, w, h) in faces:
   roi = frame[y:y+h,x:x+w]
   temp = max(roi)
   print(temp)
© www.soinside.com 2019 - 2024. All rights reserved.