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.]]
'''
相关推荐
曲幽22 分钟前
FastAPI流式输出实战与避坑指南:让AI像人一样“边想边说”
python·ai·fastapi·web·stream·chat·async·generator·ollama
Flittly36 分钟前
【从零手写 AI Agent:learn-claude-code 项目实战笔记】(1)The Agent Loop (智能体循环)
python·agent
vivo互联网技术2 小时前
ICLR2026 | 视频虚化新突破!Any-to-Bokeh 一键生成电影感连贯效果
人工智能·python·深度学习
敏编程3 小时前
一天一个Python库:virtualenv - 隔离你的Python环境,保持项目整洁
python
喝茶与编码5 小时前
Python异步并发控制:asyncio.gather 与 Semaphore 协同设计解析
后端·python
zone77396 小时前
003:RAG 入门-LangChain 读取图片数据
后端·python·面试
用户8356290780516 小时前
在 PowerPoint 中用 Python 添加和定制形状的完整教程
后端·python
用户962377954487 小时前
🚀 docx2md-picgo:Word 文档图片一键上传图床工具
python·markdown
深藏blue477 小时前
GPT-5.3 Instant 重磅上线!2026最新 ChatGPT 告别说教,国内使用与 Plus 升级教程
gpt·chatgpt·openai