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.]]
'''
相关推荐
赞奇科技Xsuperzone30 分钟前
DGX Spark 实战解析:模型选择与效率优化全指南
大数据·人工智能·gpt·spark·nvidia
读研的武41 分钟前
DashGo零基础入门 纯Python的管理系统搭建
开发语言·python
Andy1 小时前
Python基础语法4
开发语言·python
mm-q29152227292 小时前
Python+Requests零基础系统掌握接口自动化测试
开发语言·python
电院工程师3 小时前
SIMON64/128算法Verilog流水线实现(附Python实现)
python·嵌入式硬件·算法·密码学
Python图像识别4 小时前
75_基于深度学习的咖啡叶片病害检测系统(yolo11、yolov8、yolov5+UI界面+Python项目源码+模型+标注好的数据集)
python·深度学习·yolo
闲人编程4 小时前
Python游戏开发入门:Pygame实战
开发语言·python·游戏·pygame·毕设·codecapsule
雍凉明月夜5 小时前
人工智能学习中深度学习之python基础之 类
python·学习
Geo_V5 小时前
OpenAI 大模型 API 使用示例
python·chatgpt·openai·大模型应用·llm 开发