Skip to content

Commit

Permalink
fix crop
Browse files Browse the repository at this point in the history
  • Loading branch information
Bokwang0310 committed Nov 22, 2020
1 parent b668788 commit e3ed6d6
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions result/crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@
for file in files:
img_ori = cv2.imread(f'INPUT_IMAGE/{file}')
#img_ori = cv2.resize(img_ori, dsize=(0, 0), fx=0.1, fy=0.1, interpolation=cv2.INTER_AREA)
#이미지가 클 경우에만 사용
# 이미지가 클 경우에만 사용
height, width, channel = img_ori.shape
#print(height,width)
# print(height,width)

gray = cv2.cvtColor(img_ori, cv2.COLOR_BGR2GRAY)

structuringElement = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))

imgTopHat = cv2.morphologyEx(gray, cv2.MORPH_TOPHAT, structuringElement)
imgBlackHat = cv2.morphologyEx(gray, cv2.MORPH_BLACKHAT, structuringElement)
imgBlackHat = cv2.morphologyEx(
gray, cv2.MORPH_BLACKHAT, structuringElement)

imgGrayscalePlusTopHat = cv2.add(gray, imgTopHat)
gray = cv2.subtract(imgGrayscalePlusTopHat, imgBlackHat)
Expand All @@ -45,7 +46,8 @@

temp_result = np.zeros((height, width, channel), dtype=np.uint8)

cv2.drawContours(temp_result, contours=contours, contourIdx=-1, color=(255, 255, 255))
cv2.drawContours(temp_result, contours=contours,
contourIdx=-1, color=(255, 255, 255))
#cv2.drawContours(img_ori, contours=contours, contourIdx=-1, color=(255, 255, 255))

temp_result = np.zeros((height, width, channel), dtype=np.uint8)
Expand All @@ -54,8 +56,10 @@

for contour in contours:
x, y, w, h = cv2.boundingRect(contour)
cv2.rectangle(temp_result, pt1=(x, y), pt2=(x + w, y + h), color=(255, 255, 255), thickness=2)
cv2.rectangle(img_ori, pt1=(x, y), pt2=(x + w, y + h), color=(225,225,25), thickness=2)
# cv2.rectangle(temp_result, pt1=(x, y), pt2=(
# x + w, y + h), color=(255, 255, 255), thickness=2)
# cv2.rectangle(img_ori, pt1=(x, y), pt2=(x + w, y + h),
# color=(225, 225, 25), thickness=2)

# insert to dict
contours_dict.append({
Expand Down Expand Up @@ -105,10 +109,10 @@
if d['h'] >= avg_height - (avg_height*0.1) or d['w'] >= avg_width - (avg_width*0.1):
dst.append(img_ori[d['y']:d['y'] + d['h'], d['x']:d['x'] + d['w']])

cv2.imshow("img_ori", img_ori)
#cv2.imshow("temp_result", temp_result)
cv2.waitKey(0)
cv2.destroyAllWindows()
# cv2.imshow("img_ori", img_ori)
# # cv2.imshow("temp_result", temp_result)
# cv2.waitKey(0)
# cv2.destroyAllWindows()

number = 1

Expand Down

0 comments on commit e3ed6d6

Please sign in to comment.