Hi im using matplotlib to generates image of trajectory from video but it’s very slow around 1frame/second. Im looking for alternative or some how increase the generating speed.
Here is the function i use:
<code>def generate_img(video_id,track_history,trajectory_min,trajectory_max):
for trajectoryId, traj in track_history.items():
xlimMax, ylimMax, xlimMin, ylimMin = findMinMaxXY(track_history=track_history, trackID=trajectoryId)
if len(traj) < trajectory_min:
continue
if len(traj) >= trajectory_max:
traj.pop(0)
traj.pop(0)
traj = np.array(traj)
# Plot trajectories using matplotlib
fig, ax = plt.subplots(figsize=(4,4))
ax.set_xlim(xlimMin, xlimMax)
ax.set_ylim(ylimMin, ylimMax)
ax.axis('off')
ax.plot(traj[:, 0], traj[:, 1], linewidth=8)
os.makedirs(f'trajectory_image/{video_id}/', exist_ok=True)
fig.savefig(f'trajectory_image/{video_id}/{trajectoryId}.png', bbox_inches='tight')
plt.close('all')
</code>
<code>def generate_img(video_id,track_history,trajectory_min,trajectory_max):
for trajectoryId, traj in track_history.items():
xlimMax, ylimMax, xlimMin, ylimMin = findMinMaxXY(track_history=track_history, trackID=trajectoryId)
if len(traj) < trajectory_min:
continue
if len(traj) >= trajectory_max:
traj.pop(0)
traj.pop(0)
traj = np.array(traj)
# Plot trajectories using matplotlib
fig, ax = plt.subplots(figsize=(4,4))
ax.set_xlim(xlimMin, xlimMax)
ax.set_ylim(ylimMin, ylimMax)
ax.axis('off')
ax.plot(traj[:, 0], traj[:, 1], linewidth=8)
os.makedirs(f'trajectory_image/{video_id}/', exist_ok=True)
fig.savefig(f'trajectory_image/{video_id}/{trajectoryId}.png', bbox_inches='tight')
plt.close('all')
</code>
def generate_img(video_id,track_history,trajectory_min,trajectory_max):
for trajectoryId, traj in track_history.items():
xlimMax, ylimMax, xlimMin, ylimMin = findMinMaxXY(track_history=track_history, trackID=trajectoryId)
if len(traj) < trajectory_min:
continue
if len(traj) >= trajectory_max:
traj.pop(0)
traj.pop(0)
traj = np.array(traj)
# Plot trajectories using matplotlib
fig, ax = plt.subplots(figsize=(4,4))
ax.set_xlim(xlimMin, xlimMax)
ax.set_ylim(ylimMin, ylimMax)
ax.axis('off')
ax.plot(traj[:, 0], traj[:, 1], linewidth=8)
os.makedirs(f'trajectory_image/{video_id}/', exist_ok=True)
fig.savefig(f'trajectory_image/{video_id}/{trajectoryId}.png', bbox_inches='tight')
plt.close('all')
I’ve tried VisPy but the drawing is so off
PyQtGraph return QWidget: Must construct a QApplication before a QWidget
New contributor
Phi Quang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.