Skip to content

Commit

Permalink
fixing pointer code
Browse files Browse the repository at this point in the history
  • Loading branch information
shinsj4653 committed Feb 25, 2024
1 parent 40a6918 commit 07fec2d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
17 changes: 11 additions & 6 deletions OCR/googleOCR.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ def text_pointer(uri, x, y):
# 이미지 크기 출력

img_width, img_height = img.size
is_swap = False

if img_width > img_height : # 가끔 반대로 나오는 경우가 있음 -> 스와핑 시행
img_width, img_height = img_height, img_width
is_swap = True

print(f"Image Size: {img_width} x {img_height}")

print('Texts:')
Expand All @@ -205,7 +211,6 @@ def text_pointer(uri, x, y):
if i == 0: # 사진 내 전체 문자는 제외해야함
continue


x_set = set()
y_set = set()
# 가로: 4032 세로 : 3024
Expand Down Expand Up @@ -247,12 +252,12 @@ def text_pointer(uri, x, y):
# print('mid_x : ', mid_x)
# print('mid_y : ', mid_y)

#if min_x <= x <= max_x and max_y <= y :
print('min_x, x, max_x', min_x, x, max_x)
print('max_y y', max_y, y)
if max_y <= y :
print('min_x, x, max_x', min_x, x, max_x)
print('max_y y', max_y, y)
# print("거리 : math.sqrt((abs(x - mid_x) ** 2) + (abs(y - mid_y) ** 2))" )
words.append((word, math.sqrt((abs(x - mid_x) ** 2) + (abs(y - mid_y) ** 2)))) # (단어, 단어의 가운데 좌표 값과 손 좌표 간 거리)
#words.append((word, abs(y - max_y) + abs(x - mid_x)))
#words.append((word, math.sqrt((abs(x - mid_x) ** 2) + (abs(y - mid_y) ** 2)))) # (단어, 단어의 가운데 좌표 값과 손 좌표 간 거리)
words.append((word, abs(y - max_y) + abs(x - mid_x)))


words.sort(key=lambda x: x[1]) # 손과 가장 가까운 단어를 반환
Expand Down
10 changes: 5 additions & 5 deletions OCR/handLandmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ def get_finger_coordinate(uri):
# print(detection_result.hand_landmarks[0][8])
printImageInfo(uri)

print('image_shape[1] : ', image_shape[1]) # 가로
print('image_shape[0] : ', image_shape[0]) # 세로
print('image_shape[1] : ', image_shape[1]) # 가로

img_width, img_height = min(image_shape[0], image_shape[1]), max(image_shape[0], image_shape[1])

Expand All @@ -128,17 +128,17 @@ def get_finger_coordinate(uri):

for i, value in enumerate(detection_result.hand_landmarks[0]):
print("index : ", i)
print("hand x : ", value.x * image_shape[1])
print("hand y : ", value.y * image_shape[0])
print("hand x : ", value.x * img_width)
print("hand y : ", value.y * img_height)

#handXset.add(value.x)
handYset.add(value.y)

#min_x = max(handXset)
min_y = min(handYset)

#right_hand_x_coordinate = int(detection_result.hand_landmarks[0][8].x * image_shape[1])
#right_hand_y_coordinate = int(min_y * image_shape[0])
#right_hand_x_coordinate = int(detection_result.hand_landmarks[0][8].x * image_shape[0])
#right_hand_y_coordinate = int(detection_result.hand_landmarks[0][8].y * image_shape[1])

right_hand_x_coordinate = int(detection_result.hand_landmarks[0][8].x * img_width)
right_hand_y_coordinate = int(detection_result.hand_landmarks[0][8].y * img_height)
Expand Down

0 comments on commit 07fec2d

Please sign in to comment.