def write_coords(self, fd, video_buffer, buffer_idx, idx):
"""Write the coords into the given stream.
- frame number
- the index of the coords
- timestamp
- confidence
- success
- x, y, w, h,
- buffer number
- index in the buffer
:param fd: (Stream) File descriptor, String descriptor, stdout, etc
:param video_buffer: (sppasCoordsVideoBuffer)
:param buffer_idx: (int) Buffer number
:param idx: (int) An integer to write
"""
sep = self._img_writer.get_csv_sep()
coords = video_buffer.get_coordinates(idx)
frame_idx = buffer_idx * video_buffer.get_buffer_size() + idx
if len(coords) == 0:
fd.write('{:d}{:s}'.format(frame_idx + 1, sep))
fd.write('0{:s}'.format(sep))
fd.write('{:.3f}{:s}'.format(float(frame_idx) / self._fps, sep))
fd.write('none{:s}'.format(sep))
fd.write('0{:s}'.format(sep))
fd.write('0{:s}0{:s}0{:s}0{:s}'.format(sep, sep, sep, sep))
fd.write('{:d}{:s}'.format(buffer_idx + 1, sep))
fd.write('{:d}{:s}'.format(idx, sep))
fd.write('\n')
else:
radius = 0.5 / float(self._fps)
mid_time = float(frame_idx) / float(self._fps) + radius
for j in range(len(coords)):
fd.write('{:d}{:s}'.format(frame_idx + 1, sep))
fd.write('{:d}{:s}'.format(j + 1, sep))
fd.write('{:.3f}{:s}'.format(mid_time, sep))
fd.write('{:f}{:s}'.format(coords[j].get_confidence(), sep))
fd.write('1{:s}'.format(sep))
fd.write('{:d}{:s}'.format(coords[j].x, sep))
fd.write('{:d}{:s}'.format(coords[j].y, sep))
fd.write('{:d}{:s}'.format(coords[j].w, sep))
fd.write('{:d}{:s}'.format(coords[j].h, sep))
fd.write('{:d}{:s}'.format(buffer_idx + 1, sep))
fd.write('{:d}{:s}'.format(idx, sep))
fd.write('\n')