【问题标题】:how to convert temperature array to rgb array for opencv如何将温度数组转换为opencv的rgb数组
【发布时间】:2021-12-24 04:12:13
【问题描述】:

我有一个温度值数组 (320x240),我希望它转换为我指定的 rgb 值,例如:

blueRGBValue = (0,0,128)
temperatureArray =(24.532, 24.213, 24.1234, ...)
for i in range(len(temperatureArray)):
   if (temperatureArray[i] > 25 and temperatureArray[i]<=30):
   imageArray.append(blueRGBValue)
...

对所有温度数组都像这样,但我不能将 rgb 代码作为元组分配给 imageArray。我怎样才能做到这一点? 我的 imageArray 应该首先作为 numpy.zeros 启动为 ndarray

感谢您的建议。

【问题讨论】:

  • 我假设您的数组是 320x240 并且在每个位置都包含一个浮点值。请使用np.savetxt() 保存。我想你有一些可以将温度映射到颜色的东西。请彻底澄清。那么请分享所有这些信息——您可能需要使用 Dropbox 或 Google Drive。谢谢。

标签: python arrays numpy opencv


【解决方案1】:

要将 rgb 元组存储到 np 数组中,您必须按如下方式初始化 imageArray:

imageArray = np.zeros((size), dtype=(float,3))

注意 dtype,您将 3 个类型的浮点数存储到您的元组中。 然后你可以用imageArray[0] = rgb添加你的rgb值

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-27
    • 2018-09-28
    • 1970-01-01
    • 2016-12-17
    • 2016-11-24
    相关资源
    最近更新 更多