solved error when closing window

This commit is contained in:
davidpagnon 2023-09-12 00:10:50 +02:00
parent 18ebbaa79f
commit 26e74bf320

View File

@ -27,6 +27,10 @@
''' '''
# TODO: DETECT WHEN WINDOW IS CLOSED
# TODO: WHEN 'Y', CATCH IF NUMBER OF IMAGE POINTS CLICKED NOT EQUAL TO NB OBJ POINTS
# REMOVE OPENCV ERROR (FROM FFMPEG C CODE)
## INIT ## INIT
from Pose2Sim.common import RT_qca2cv, rotate_cam, quat2mat, euclidean_distance, natural_sort from Pose2Sim.common import RT_qca2cv, rotate_cam, quat2mat, euclidean_distance, natural_sort
@ -546,6 +550,16 @@ def calibrate_extrinsics(calib_dir, extrinsics_config_dict, C, S, K, D):
# Check calibration results # Check calibration results
if show_reprojection_error: if show_reprojection_error:
# Reopen image, otherwise 2 sets of text are overlaid
try:
cap = cv2.VideoCapture(img_vid_files[0])
res, img = cap.read()
if res == False:
raise
except:
img = cv2.imread(img_vid_files[0])
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
for o in proj_obj: for o in proj_obj:
cv2.circle(img, (int(o[0]), int(o[1])), 8, (0,0,255), -1) cv2.circle(img, (int(o[0]), int(o[1])), 8, (0,0,255), -1)
for i in imgp: for i in imgp:
@ -673,14 +687,6 @@ def imgp_objp_visualizer_clicker(img, imgp=[], objp=[], img_path=''):
''' '''
def on_close(event):
# If close window, close all and return nothing
global imgp_confirmed, objp_confirmed
plt.close('all')
imgp_confirmed = []
objp_confirmed = []
def on_key(event): def on_key(event):
''' '''
Handles key press events: Handles key press events:
@ -803,11 +809,12 @@ def imgp_objp_visualizer_clicker(img, imgp=[], objp=[], img_path=''):
ax_3d.scatter(*objp[count], marker='o', color='g') ax_3d.scatter(*objp[count], marker='o', color='g')
fig_3d.canvas.draw() fig_3d.canvas.draw()
elif count == len(objp)-1: elif count == len(objp)-1:
# close all
plt.close('all')
# retrieve objp_confirmed # retrieve objp_confirmed
objp_confirmed = np.array([[objp[count]] if 'objp_confirmed' not in globals() else objp_confirmed+[objp[count]]][0]) objp_confirmed = np.array([[objp[count]] if 'objp_confirmed' not in globals() else objp_confirmed+[objp[count]]][0])
imgp_confirmed = np.array(imgp_confirmed, np.float32) imgp_confirmed = np.array(imgp_confirmed, np.float32)
# close all, delete all # delete all
plt.close('all')
for var_to_delete in ['events', 'count', 'scat', 'scat_3d', 'fig_3d', 'ax_3d', 'objp_confirmed_notok']: for var_to_delete in ['events', 'count', 'scat', 'scat_3d', 'fig_3d', 'ax_3d', 'objp_confirmed_notok']:
if var_to_delete in globals(): if var_to_delete in globals():
del globals()[var_to_delete] del globals()[var_to_delete]
@ -918,7 +925,6 @@ def imgp_objp_visualizer_clicker(img, imgp=[], objp=[], img_path=''):
# Handles key presses to Accept, dismiss, or click points by hand # Handles key presses to Accept, dismiss, or click points by hand
cid = fig.canvas.mpl_connect('key_press_event', on_key) cid = fig.canvas.mpl_connect('key_press_event', on_key)
fig.canvas.mpl_connect('close_event', on_close)
plt.draw() plt.draw()
plt.show(block=True) plt.show(block=True)