问题描述
我使用的是 RaspBerry Pi 4 和 HTPA32x32d 热像仪传感器。我正在使用 https://github.com/cjcbusatto/thermografree 这个叉子通过 I2C 读取相机。我的主要代码采用 32x32 传感器输出并使用 cv2.resize() 函数转换为可见图像并显示在屏幕上。我的范围在 2-4 fps 之间。我想提高实时热成像的 fps。你有什么建议可以提高我的 fps 吗?
我正在考虑预测帧数,但我不知道一种方法,或者它是否足以用于实时 fps 增量?如果没有,或者您有更好的方法,我可以使用这些信息。
更新 #1
我还没有尝试过任何东西。我正在寻找提高fps的方法。我有一个想法,收集 3 帧并预测它们之间的几帧以增加到 10 fps。由于视频的 2 帧之间的变化最小。但我不知道如何开始。
示例代码如下:
#IMPORT PACKAGES
import time
import cv2
import numpy as np
from htpa import *
size = (256,256) #frame size
#initialize IR camera module
ir = HTPA(0x1A)
while(1):
start_time = time.time()
#generate termal image and temperature array
temps,ta = ir.capture_temperatures()
irIm = cv2.resize(temps,size,interpolation = cv2.INTER_CUBIC)
norm_image = np.uint8(cv2.normalize(irIm,None,alpha = 0,beta = 255,norm_type = cv2.norM_MINMAX,dtype = cv2.CV_8UC1))
hotIm = cv2.applyColorMap(norm_image,cv2.COLORMAP_HOT)
cv2.imshow("Result",hotIm)
key = cv2.waitKey(1) & 0xFF
print("fps ; ",1.0/(time.time()-start_time))
#if the 'q' key was pressed,break from the loop
if key == ord("q"):
break
cv2.destroyAllWindows()
相机源的示例帧:
更新#2
当我只读取 temps,ta = ir.capture_temperatures()
而没有任何处理(甚至显示)时,fps 的平均值为 4.0,在 3.2 到 4.2 之间移动。
读取和处理(未显示)时,fps 在 3.0 和 4.0 之间移动,平均值为 3.7。
解决方法
我查看了 htpa32x32d 的数据表。我看到这个解决方案 enter image description here 在 htpa.py 中:
def set_clock_speed(self,clk):
if clk > 63:
clk = 63
if clk < 0:
clk = 0
clk = int(clk)
print(clk)
clk_speed = self.generate_command(0x06,clk)
self.send_command(clk_speed)
您可以更改 clk 值,这样就解决了您的问题。
,查看代码,htpa.py
中的第 252 行可能是导致延迟的原因。
while not self.block_capture_finished(block,blind,vdd):
time.sleep(0.005)
尝试time.sleep(0.001)
,看看是否有任何改进。
另一个原因可能是在 capture_display.py
第 20 行中使用了调整大小。
试试im = cv2.resize(im,None,fx=4,fy=4)