我下载了许多图像以制作模型,但我遇到制作边界框的问题。 问题是,当我运行代码时,同时弹出所有照片时,我尝试了多种方法使其按顺序显示,但没有用 加上这张打开的最后一张照片,我可以在上面绘制盒子了,但是其他照片不允许我在上面绘制盒子
import os
import cv2
from matplotlib.widgets import RectangleSelector
import matplotlib.pyplot as plt
关闭打开的照片的功能
def onkeypress(event):
global object_list
global tl_list
global br_list
global img
if event.key =='q':
print(tl_list, br_list)
tl_list = []
br_list = []
object_list = []
img = None
plt.close()
这是打开照片和画框的循环
if __name__ == '__main__' :
for n, image_file in enumerate(os.scandir(image_folder)):
img = image_file
fig, ax = plt.subplots(1)
#mngr = plt.get_current_fig_manager()
#mngr.window.setGeometry(250, 120, 1280, 1024)
image = cv2.imread(image_file.path)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
ax.imshow(image)
toggle_selector.RS = RectangleSelector(
ax, line_select_callback,
drawtype = 'box', useblit = True,
button = [1], minspanx = 5, minspany = 5,
spancoords = 'pixels', interactive = True
)
#plt.connect('button_press_event', line_select_callback)
bbox = plt.connect('key_press_event', toggle_selector)
key = plt.connect('key_press_event', onkeypress)
#cv2.waitKey(0)
plt.imshow(image)
plt.show()
我希望目录中的照片输出打开并确定边界框,然后按“ q”将其关闭并打开下一个,依此类推