Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
liupeng89 committed May 8, 2018
1 parent 980693d commit e7b20db
Show file tree
Hide file tree
Showing 3 changed files with 354 additions and 221 deletions.
4 changes: 3 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
from utils.Functions import getConnectedComponents, getContourOfImage, getSkeletonOfImage, removeBreakPointsOfContour, \
removeBranchOfSkeletonLine, removeBranchOfSkeleton, getEndPointsOfSkeletonLine, \
getCrossPointsOfSkeletonLine, sortPointsOnContourOfImage, min_distance_point2pointlist, \
getNumberOfValidPixels, segmentContourBasedOnCornerPoints, merge_corner_lines_to_point
getNumberOfValidPixels, segmentContourBasedOnCornerPoints, merge_corner_lines_to_point, \
fitCurve, draw_cubic_bezier

# 1133壬 2252支 0631叟
path = "0631叟.jpg"
Expand All @@ -23,6 +24,7 @@
contour_points_sorted = sortPointsOnContourOfImage(contour)
print("contour points num:%d" % len(contour_points_sorted))


img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
_, img = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY)
print(img.shape)
Expand Down
74 changes: 54 additions & 20 deletions test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,30 +255,64 @@
#
# print(isSubList(a, b))

import cv2
import numpy as np
from skimage import feature

from utils.Functions import createBlankGrayscaleImage, createBlankRGBImage

# import cv2
# import numpy as np
# from skimage import feature
#
# from utils.Functions import createBlankGrayscaleImage, createBlankRGBImage
#
#
# # 1133壬 2252支 0631叟
# path = "0631叟.jpg"
#
# img = cv2.imread(path, 0)
# _, img = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY)
# img_rbg = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
#
# edges = feature.canny(img)
# edges1 = feature.canny(img, sigma=3)
#
# print(edges)
#
# contour_gray = createBlankGrayscaleImage(img)
# contour_rgb = createBlankRGBImage(img)
#
# cv2.imshow("edge", edges)
# cv2.imshow("edge1", edges1)
#
# cv2.waitKey(0)
# cv2.destroyAllWindows()

# 1133壬 2252支 0631叟
path = "0631叟.jpg"
import numpy as np

img = cv2.imread(path, 0)
_, img = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY)
img_rbg = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)

edges = feature.canny(img)
edges1 = feature.canny(img, sigma=3)
def medfilt (x, k):
"""Apply a length-k median filter to a 1D array x.
Boundaries are extended by repeating endpoints.
"""
assert k % 2 == 1, "Median filter length must be odd."
assert x.ndim == 1, "Input must be one-dimensional."
k2 = (k - 1) // 2
y = np.zeros ((len (x), k), dtype=x.dtype)
y[:,k2] = x
for i in range (k2):
j = k2 - i
y[j:,i] = x[:-j]
y[:j,i] = x[0]
y[:-j,-(i+1)] = x[j:]
y[-j:,-(i+1)] = x[-1]
return np.median (y, axis=1)

print(edges)

contour_gray = createBlankGrayscaleImage(img)
contour_rgb = createBlankRGBImage(img)
def test ():
import pylab as p
x = np.linspace (0, 1, 101)
x[3::10] = 1.5
p.plot (x)
p.plot (medfilt (x,3))
p.plot (medfilt (x,5))
p.show ()

cv2.imshow("edge", edges)
cv2.imshow("edge1", edges1)

cv2.waitKey(0)
cv2.destroyAllWindows()
if __name__ == '__main__':
test ()
Loading

0 comments on commit e7b20db

Please sign in to comment.