I want to label the images I want to use for AI, but it is troublesome to create a GUI. .. .. I thought I wondered if it could be done on JupyterLab, and I did a lot of research, so I made a note at that time. An image like inputting labeling with input while updating the image displayed with matplot.
Label the images in the sample_img folder.
import cv2
import matplotlib.pyplot as plt
import os
import glob
import IPython
#Get the path of the image
img_list = glob.glob(os.path.join(r"sample_img","*.jpg "))
img_list
>>> ['sample_img/img3.jpg', 'sample_img/img2.jpg', 'sample_img/img1.jpg']
name_list = []
for img_path in img_list:
#Loading images
img = cv2.imread(img_path)
#Frame to display image
fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(1,1,1)
ax.imshow(cv2.cvtColor(img,cv2.COLOR_BGR2RGB))
plt.title(img_path)
plt.pause(.01)
#Text box for labeling
comment = input()
if comment == "break":
break
else:
#Clear the displayed image
IPython.display.clear_output()
#Add the string entered in Input to the list
name_list.append(comment)
The operation screen looks like this. pass
# name_Check list
name_list
>>> ['dog', 'cat', 'cat']
I wish I could make the Input part look like a radio button.
Recommended Posts