【问题标题】:Is there a way of increasing fps of real time camera feed in raspberry pi?有没有办法在树莓派中增加实时摄像头的帧率?
【发布时间】:2021-05-26 17:16:07
【问题描述】:

我正在使用 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。

【问题讨论】:

  • 请包含您正在使用的实际代码及其输出,以便用户提供帮助。你试过什么?结果如何?研究?
  • 尝试纯粹对 100 帧的捕获(绝对不进行处理或显示)进行计时。这将为您提供您希望达到的最佳帧速率。然后尝试捕获 1 帧并处理时间以一遍又一遍地处理它(没有任何显示)100 次。然后报告结果。
  • 如果我不理解您的问题@MarkSetchell,请按您的意愿更新。
  • capture_temperature() 调用 capture_image() 调用 expose_block() 四次,内部等待 5ms - 这确实设置了您将获得多快的上限。也许尝试减少第 43 行的 5ms 延迟,看看它是否稳定在 3ms 或 2ms...
  • 它没有改变任何东西,只观察到 0.1 fps 的增加。它与硬件和 I2C 速度限制有关。但是制造商的程序以 10 fps 运行。我之前有测试套件来测试传感器。

标签: python opencv raspberry-pi signal-processing frame-rate


【解决方案1】:

我查看了 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 值,这样就解决了您的问题。

【讨论】:

    【解决方案2】:

    Link to source code

    查看代码,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)

    【讨论】:

    • 不幸的是,它只是有帮助,因为它将结果从 4.0 变为 4.1 fps。
    猜你喜欢
    • 1970-01-01
    • 2017-05-12
    • 1970-01-01
    • 1970-01-01
    • 2017-06-07
    • 1970-01-01
    • 2017-12-23
    • 2020-11-05
    • 2021-08-11
    相关资源
    最近更新 更多