我从SQL搜索中收到了一个字典,然后我想遍历字典以在x,y,h,w上裁剪图像。然后,我想显示原始图像,即编辑后的图像。我已经完成了。我无法弄清楚的是如何使用matplotlib.pyplot在图中显示结果。这是我的代码:
sql_result = get_rois(config, "145", "a")
img_dir = '../imgs/'
make palaeographical chart
fig = plt.figure()
#Iterate over the list
for num, result in enumerate(aleph_rois):
#make path to image
img_path = os.path.join(imgs, sql_result['file_name'])
#declare variables for cropping character
x = sql_result['x']
y = sql_result['y']
w = sql_result['w']
h = sql_result['h']
#crop to character
img = cv2.imread(img_path, 0)
crop = img[y:y+h, x:x+w]
th0 = cv2.adaptiveThreshold(crop, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 21, 2)
#OTSU Binarization to fill
blur = cv2.GaussianBlur(crop,(5,5),0)
ret, th1 = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
frg_loc = str(sql_result['artefact_siglum']) + " " + str(result['line_id']) + " roi:" + str(sql_result['roi_id'])
#create fig
plt.title(frg_loc)
plt.imshow(th1, cmap='Greys_r')
以上显然是失败的。我尝试了几种选择,但我认为图像存在图像相互覆盖的问题。但是目标是使th0和th1处于2列图中,并且行数由sql_results中的结果数定义。很感谢任何形式的帮助。谢谢。