2021SC@SDUSC
我们接着来分析slidingWindowsEval函数
在上一次分析中,我们提到,作者调用了他自己写的函数searchOptimalCuttingPoint,找到了最佳分割点,这个点是一个列表,因为点不止一个,然后点列表和评价点的分割score组成的总体列表,作为res返回原函数中,接下来,作者用cutting_pts = res[1],将点集取出来存放到cutting_pts里面,这样就可以分割了。以下是分割部分的代码:
for x in range(1,len(cutting_pts)):
if x != len(cutting_pts)-1 and x!=1:
section = image[0:36,cutting_pts[x-1]-2:cutting_pts[x]+2]
elif x==1:
c_head = cutting_pts[x - 1]- 2
if c_head<0:
c_head=0
c_tail = cutting_pts[x] + 2
section = image[0:36, c_head:c_tail]
elif x==len(cutting_pts)-1:
end = cutting_pts[x]
diff = image.shape[1]-end
c_head = cutting_pts[x - 1]
c_tail = cutting_pts[x]
if diff<7 :
section = image[0:36, c_head-5:c_tail+5]
else:
diff-=1
section = image[0:36, c_head - diff:c_tail + diff]
elif x==2:
section = image[0:36, cutting_pts[x - 1] - 3:cutting_pts[x-1]+ mid]
else:
section = image[0:36,cutting_pts[x-1]:cutting_pts[x]]
seg_block.append(section)
refined = refineCrop(seg_block,mid-1)
这里进行了分支,因为如果x是最佳分割点点集中间的点、开头的点、末尾的点,具体如何分割都是不同的,如果是位于开头或末尾,由于涉及图像边缘,所以裁剪的时候给出的坐标要格外小心。裁剪的部分是section,然后保存在seg_block里面。最后seg_block还提交给refineCrop函数进行进一步的修剪。
t0 = time.time()
for i,one in enumerate(refined):
res_pre = cRP.SimplePredict(one, i )
# cv2.imshow(str(i),one)
# cv2.waitKey(0)
confidence+=res_pre[0]
name+= res_pre[1]
print("字符识别",time.time() - t0)
return refined,name,confidence
修剪完了之后,图像就可以识别了,接下来就进行最终的识别,识别出的文字和置信度保存在confidence和name中并且返回给主函数。