这种只能存储最后一次的数据 想把所有的数据保留 如何修改呢
import csv
def execute(change):
image = change['new']
#print("-", image.shape[0], image.shape[1], image.shape[2])
data = preprocess(image)
#print(data.shape[0], data.shape[1], data.shape[2])
cmap, paf = model_trt(data)
cmap, paf = cmap.detach().cpu(), paf.detach().cpu()
counts, objects, peaks = parse_objects(cmap, paf)#, cmap_threshold=0.15, link_threshold=0.15)
draw_objects(image, counts, objects, peaks)
image_w.value = bgr8_to_jpeg(image[:, ::-1, :])
a=[]
f = open('test.csv','w',encoding='utf-8',newline='')
csv_writer = csv.writer(f)
firstRow = ['x','y','counts','time']
csv_writer.writerow(firstRow)
height = image.shape[0]
width = image.shape[1]
K = topology.shape[0]
count = int(counts[0])
K = topology.shape[0]
#print(count)
for i in range(count):
color = (0, 255, 0)
obj = objects[0][i]
C = obj.shape[0]
for j in range(C):
k = int(obj[j])
if k >= 0:
peak = peaks[0][j][k]
x = round(float(peak[1]) * width)
y = round(float(peak[0]) * height)
#cv2.circle(image, (x, y), 3, color, 2)
#print("x = %d, y = %d\n"%(x,y))
list = [x, y,i,time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(int(time.time())))]
#print(list)
#a.append(list)
csv_writer.writerow(list)
f.close()