def plotRectangles(rects,transcriptions,bgrImg,rgbCol):
bgrCol=np.array(rgbCol)[[2,1,0]]
res=bgrImg.copy()
pts=np.empty([rects.shape[0],5,1,2])
if rects.shape[1]==4:
x=rects[:,[0,2,2,0,0]]
y=rects[:,[1,1,3,3,1]]
elif rects.shape[1]==8:
x=rects[:,[0,2,4,6,0]]
y=rects[:,[1,3,5,7,1]]
else:
raise Exception()
pts[:,:,0,0]=x
pts[:,:,0,1]=y
pts=pts.astype('int32')
ptList=[pts[k,:,:,:] for k in range(pts.shape[0])]
if not (transcriptions is None):
for rectNum in range(rects.shape[0]):
res=cv2.putText(res,transcriptions[rectNum],(rects[rectNum,0],rects[rectNum,1]),1,cv2.FONT_HERSHEY_PLAIN,bgrCol)
res=cv2.polylines(res,ptList,False,bgrCol)
return res
评论列表
文章目录