gpt优化事件处理速度

1、优化时间戳累加时间

python 复制代码
# 原代码
for j in range(evs_duration_num):
            img_conf[int(y_array[j]), int(x_array[j])] += int(time_array[j])


# 现代码
import numpy as np

y_array = [1, 2, 2, 4, 3]
x_array = [1, 2, 2, 4, 3]
time_array = [10, 11, 12, 13, 14]

img_conf = np.zeros(shape=(5,5), dtype=np.float64)
print(img_conf)
xy_column_stack = np.column_stack((y_array, x_array))
print(f"xy_column_stack: \n{xy_column_stack}")
unique_indices, inverse_indices = np.unique(xy_column_stack, axis=0, return_inverse=True)
print(f"unique_indices: \n{unique_indices}")
print(f"inverse_indices: \n{inverse_indices}")
time_array_sum = np.bincount(inverse_indices, weights=time_array).astype(float)
print(f"time_array_sum: \n{time_array_sum}")
img_conf[unique_indices[:, 0], unique_indices[:, 1]] = time_array_sum
print(img_conf)

2、 生成map图

python 复制代码
# 原代码
for polarity, xx, yy in zip(p_list, x_list, y_list):
    yy, xx = int(yy), int(xx)

    # 正事件为红色,负事件为蓝色,numpy:BGR
    if polarity == 1:
        map[yy][xx][0] = 0
        map[yy][xx][1] = 0
        map[yy][xx][2] = 255
    elif polarity == 0:
        map[yy][xx][0] = 255
        map[yy][xx][1] = 0
        map[yy][xx][2] = 0
    else:
        raise BaseException(f"极性错误!({xx},{yy}) {polarity} {save_map_path}")


# 现代码
# 创建一个全白色 (RGB: 255, 255, 255) 的图像,数据类型为uint8
map = np.ones((height, width, 3), dtype=np.uint8) * 255

# 将坐标和极性转换为numpy数组
x_list = np.array(x_list, dtype=int)
y_list = np.array(y_list, dtype=int)
p_list = np.array(p_list, dtype=int)

# 使用向量化操作设置颜色
# 极性为1的坐标设置为红色
red_mask = p_list == 1
map[y_list[red_mask], x_list[red_mask], 0] = 0
map[y_list[red_mask], x_list[red_mask], 1] = 0
map[y_list[red_mask], x_list[red_mask], 2] = 255

# 极性为0的坐标设置为蓝色
blue_mask = p_list == 0
map[y_list[blue_mask], x_list[blue_mask], 0] = 255
map[y_list[blue_mask], x_list[blue_mask], 1] = 0
map[y_list[blue_mask], x_list[blue_mask], 2] = 0

# 保存图像
cv2.imwrite(str(save_map_path), map)

'''
[[0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0.]
 [0. 0. 0. 0. 0.]]
xy_column_stack:
[[1 1]
 [2 2]
 [2 2]
 [4 4]
 [3 3]]
unique_indices:
[[1 1]
 [2 2]
 [3 3]
 [4 4]]
inverse_indices:
[0 1 1 3 2]
time_array_sum:
[10. 23. 14. 13.]
[[ 0.  0.  0.  0.  0.]
 [ 0. 10.  0.  0.  0.]
 [ 0.  0. 23.  0.  0.]
 [ 0.  0.  0. 14.  0.]
 [ 0.  0.  0.  0. 13.]]
'''
相关推荐
kobe_OKOK_11 小时前
DRF接口幂等操作
python·django
chunmiao303212 小时前
GPT-5.6上线Kiro平台:AI编程降价潮下模型怎么选
gpt·ai编程
廿士12 小时前
python脚本使用相关
python
青 春 记 忆12 小时前
零基础入门python19:Flask账本第一步——应用工厂、蓝图和健康检查
python·flask·后端开发
朦胧之12 小时前
Python 后端核心知识
python
denggun1234513 小时前
yield
前端·数据库·python
zx_7414848114 小时前
【Python 入门】面向对象基础:类、对象、成员变量与构造方法
开发语言·python
招财小梗14 小时前
沈阳商贸公司AI企业服务优势几何?
大数据·人工智能·python
ZISHU_98715 小时前
用 TLabel 给 SynTouch BioTac 数据做语义标注:从原始信号到结构化标注
开发语言·人工智能·python·数据·机器人触觉
m0_6174939416 小时前
SSLError [ASN1: NOT_ENOUGH_DATA] 问题排查与解决指南
python·ssl