Exemple #1
0
imgbin = getBinaryImage(getGrayscaleImage(img))
imgbin = 255 - dilate(erode(imgbin, 1), 1)

contours = getImageContours(imgbin)
contourSets = geom.mergeContours(contours, mergCrit)
imObjs = getBinaryImageObjectsFromContourSets(imgbin, contourSets)

# ------------------------------
angle, center = geom.getBinaryImgObjectsAngleAndCenter(imObjs)
imgbin = getRotatedImage(imgbin, angle, center)
imgbin = getBinaryImage(imgbin)
# ------------------------------


contours = getImageContours(imgbin)
contourSets = geom.mergeContours(contours, mergCrit)
imObjs = getBinaryImageObjectsFromContourSets(imgbin, contourSets)

imObjs = sorted(imObjs, key=lambda o: o[0][0])

displayImageGrid(([imo[1] for imo in imObjs]), 1, plotImage)
plt.show()

rowImObjs = imObjs
distances = np.array(geom.getConsecutiveXDistancesBetweenRects(geom.imObjToRects(rowImObjs)))
kmeans = geom.getKMeans(2, distances.reshape(len(distances), 1))
classificationInput = [nn.transformImageForAnn(obj[1]) for obj in rowImObjs]
outputIndices = nn.classify(ann, classificationInput)
print nn.getStringOutputWithSpaces(outputIndices, kmeans.labels_, alphabet)
Exemple #2
0
imgbin = getBinaryImage(getGrayscaleImage(img))
imgbin = dilate(erode(imgbin,2),1)

imObjs = getBinaryImageObjects(imgbin)

#------------------------------
angle, center = geom.getBinaryImgObjectsAngleAndCenter(imObjs)
imgbin = getRotatedImage(imgbin, angle, center)
imgbin = getBinaryImage(imgbin)
#------------------------------

imObjs = getBinaryImageObjects(imgbin)

imObjsY = np.array([io[0][1] for io in imObjs])

kmeans = geom.getKMeans(2, imObjsY.reshape(len(imObjsY), 1))

rows  =  geom.partition(imObjs, kmeans.labels_, 2)

rowsWithY = sorted(zip(rows, kmeans.cluster_centers_), key = lambda i: i[1])

rows = zip(*rowsWithY)[0]

plt.figure()

displayImageGrid([imo[1] for imo in imObjs], 5, plotImage)

#-------------------------------------------------

for row in rows:
	rowImObjs = sorted(row, key = lambda o: o[0][0])