我是 python 新手。我正在尝试开发一个 GUI 来使用 tknter 标记和分类图像。我需要将普通图像转换为 SLIC 超像素图像,如图所示。获得 SLIC 图像后,我应该能够选择该图像的各个片段并相应地标记。我只有两节课。目前我从 path 加载图像,然后将它们转换为 SLIC 图像。然后单击任意点以捕获该特定点上的 RGB 值和 X、Y 坐标以进行标记。这是我正在使用的代码。
def _load_image(path):
"""
Loads and resizes an image from a given path using the Pillow library
:param path: Path to image
:return: Resized or original image
"""
#head,tail = os.path.split(path)
#tail.replace('.jpg','.txt')
def click_event(event,x,y,flags,params):
if event == cv2.EVENT_LBUTTONDOWN or event==cv2.EVENT_RBUTTONDOWN:
file = open('resultee.txt','a+')
file.write("Root at Co-Ordinates ({}, {}) with RGB {} in file {}\n".format(x,y,image[x][y],path))
file.close()
image = cv2.imread(path)
segments = slic(img_as_float(image), n_segments = 100, compactness=30, sigma = 1)
pimg=mark_boundaries(img_as_float(cv2.cvtColor(image,cv2.COLOR_BGR2RGB)), segments)
cv2.imshow('image',pimg)
cv2.setMouseCallback('image',click_event)
cv2.waitKey()
cv2.destroyAllWindows()
return pimg