-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
660 additions
and
28 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# coding: utf-8 | ||
import cv2 | ||
import numpy as np | ||
|
||
from utils.Functions import getConnectedComponents | ||
|
||
|
||
def extractStrokesFromRadical(radical): | ||
""" | ||
Stroke extracting from one radical. | ||
:param radical: | ||
:return: | ||
""" | ||
if radical is None: | ||
return | ||
|
||
|
||
|
||
def autoStrokeExtractiing(image): | ||
""" | ||
Automatic strokes extracting | ||
:param image: grayscale image | ||
:return: strokes images with same size | ||
""" | ||
if image is None: | ||
return | ||
|
||
# get connected components | ||
radicals = getConnectedComponents(image) | ||
print("radicals num: %d" % len(radicals)) | ||
|
||
# strokes | ||
total_strokes = [] | ||
for rad in radicals: | ||
strokes = extractStrokesFromRadical(rad) | ||
total_strokes += strokes | ||
|
||
return total_strokes | ||
|
||
|
||
def main(): | ||
path = "1133壬.jpg" | ||
|
||
img = cv2.imread(path, 0) | ||
_, img = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY) | ||
|
||
img = np.array(img, dtype=np.uint8) | ||
|
||
strokes = autoStrokeExtractiing(img) | ||
|
||
# print("storke num :%d" % len(strokes)) | ||
# | ||
# for i in range(len(strokes)): | ||
# cv2.imshow("stroke_%d"%i, strokes[i]) | ||
|
||
cv2.waitKey(0) | ||
cv2.destroyAllWindows() | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.