Skip to content

Commit

Permalink
update for pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
fcakyon committed Apr 1, 2020
1 parent 01df17a commit 4e79c50
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
1 change: 0 additions & 1 deletion craft_text_detector/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,5 @@ def detect_text(image_path,
heatmap=prediction_result["heatmap"],
output_dir=output_dir)


# return prediction results
return prediction_result
10 changes: 5 additions & 5 deletions craft_text_detector/craft_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

def warpCoord(Minv, pt):
out = np.matmul(Minv, (pt[0], pt[1], 1))
return np.array([out[0]/out[2], out[1]/out[2]])
return np.array([out[0] / out[2], out[1] / out[2]])


""" end of auxilary functions """
Expand All @@ -33,7 +33,7 @@ def getDetBoxes_core(textmap, linkmap,

text_score_comb = np.clip(text_score + link_score, 0, 1)
nLabels, labels, stats, centroids = cv2.connectedComponentsWithStats(
text_score_comb.astype(np.uint8), connectivity=4)
text_score_comb.astype(np.uint8), connectivity=4)

det = []
mapper = []
Expand Down Expand Up @@ -90,7 +90,7 @@ def getDetBoxes_core(textmap, linkmap,

# make clock-wise order
startidx = box.sum(axis=1).argmin()
box = np.roll(box, 4-startidx, 0)
box = np.roll(box, 4 - startidx, 0)
box = np.array(box)

det.append(box)
Expand Down Expand Up @@ -186,8 +186,8 @@ def getPoly_core(boxes, labels, mapper, linkmap):
continue # No polygon area

if prev_h < cur_h:
pp[int((seg_num - 1)/2)] = (x, cy)
seg_height[int((seg_num - 1)/2)] = cur_h
pp[int((seg_num - 1) / 2)] = (x, cy)
seg_height[int((seg_num - 1) / 2)] = cur_h
prev_h = cur_h

# processing last segment
Expand Down
14 changes: 7 additions & 7 deletions craft_text_detector/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,21 @@ def rectify_poly(img, poly):
width = 0
height = 0
for k in range(n):
box = np.float32([poly[k], poly[k+1], poly[-k-2], poly[-k-1]])
width += int((np.linalg.norm(box[0] - box[1]) + np.linalg.norm(box[2] - box[3]))/2)
box = np.float32([poly[k], poly[k + 1], poly[-k - 2], poly[-k - 1]])
width += int((np.linalg.norm(box[0] - box[1]) + np.linalg.norm(box[2] - box[3])) / 2)
height += np.linalg.norm(box[1] - box[2])
width = int(width)
height = int(height / n)

output_img = np.zeros((height, width, 3), dtype=np.uint8)
width_step = 0
for k in range(n):
box = np.float32([poly[k], poly[k+1], poly[-k-2], poly[-k-1]])
w = int((np.linalg.norm(box[0] - box[1]) + np.linalg.norm(box[2] - box[3]))/2)
box = np.float32([poly[k], poly[k + 1], poly[-k - 2], poly[-k - 1]])
w = int((np.linalg.norm(box[0] - box[1]) + np.linalg.norm(box[2] - box[3])) / 2)

# Top triangle
pts1 = box[:3]
pts2 = np.float32([[width_step, 0], [width_step + w - 1, 0], [width_step + w - 1, height-1]])
pts2 = np.float32([[width_step, 0], [width_step + w - 1, 0], [width_step + w - 1, height - 1]])
M = cv2.getAffineTransform(pts1, pts2)
warped_img = cv2.warpAffine(img, M, (width, height), borderMode=cv2.BORDER_REPLICATE)
warped_mask = np.zeros((height, width, 3), dtype=np.uint8)
Expand All @@ -123,12 +123,12 @@ def rectify_poly(img, poly):

# Bottom triangle
pts1 = np.vstack((box[0], box[2:]))
pts2 = np.float32([[width_step, 0], [width_step + w - 1, height-1], [width_step, height-1]])
pts2 = np.float32([[width_step, 0], [width_step + w - 1, height-1], [width_step, height - 1]])
M = cv2.getAffineTransform(pts1, pts2)
warped_img = cv2.warpAffine(img, M, (width, height), borderMode=cv2.BORDER_REPLICATE)
warped_mask = np.zeros((height, width, 3), dtype=np.uint8)
warped_mask = cv2.fillConvexPoly(warped_mask, np.int32(pts2), (1, 1, 1))
cv2.line(warped_mask, (width_step, 0), (width_step + w - 1, height-1), (0, 0, 0), 1)
cv2.line(warped_mask, (width_step, 0), (width_step + w - 1, height - 1), (0, 0, 0), 1)
output_img[warped_mask == 1] = warped_img[warped_mask == 1]

width_step += w
Expand Down
4 changes: 2 additions & 2 deletions craft_text_detector/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,13 @@ def get_prediction(image,
# calculate box coords as ratios to image size
boxes_as_ratio = []
for box in boxes:
boxes_as_ratio.append(box/[img_width, img_height])
boxes_as_ratio.append(box / [img_width, img_height])
boxes_as_ratio = np.array(boxes_as_ratio)

# calculate poly coords as ratios to image size
polys_as_ratio = []
for poly in polys:
polys_as_ratio.append(poly/[img_width, img_height])
polys_as_ratio.append(poly / [img_width, img_height])
polys_as_ratio = np.array(polys_as_ratio)

return {"boxes": boxes,
Expand Down

0 comments on commit 4e79c50

Please sign in to comment.