posenet을 활용한 제스처 제어 보고서 #50
Beantree09
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
서론
이번 프로젝트는 카메라를 사용해 사용자의 제스처를 캡처하고 서버로 전송한 뒤 서버에서 프레임을 분석하여 Posenet을 이용해 제스처를 인식합니다.
제스처를 인식하고 서버에서 데이터를 처리하고 결과를 return하기 위해 사용자의 제스처를 연산 및 처리하는 기능을 담당하는 gesture_mode.py와 gesture_mode.py에서 사용하는 여러 메소드가 포함된 Parts 클래스를 정의하는 parts.py모듈을 제작하였습니다.
main에서 받아온 데이터를 처리하는 gesture_mode.py는 사용자의 제스처를 연산 및 처리하는 기능을 담당하고 있으며, 처리한 데이터와 값을 main에 return하여 Raspberry PI를 통해 TV를 작동 및 제어하는 기능을 수행하고 있습니다.
gesture_mode.py에 사용되는 다양한 함수들의 연산을 처리하고 Parts의 객체를 담고 있는 parts.py 모듈은 gesture_mode.py에서 import되어데이터 처리에 활용됩니다.
gesture_mode.py
get_command_1_2
get_command_1_2(parts, command) 함수는 parts.intital_position에 저장되어 있는 시작지점을 기준으로 왼손인지 오른손인지 구분을 하여 손(손목)의 좌표를 계산하고 손(손목)이 x좌표 기준으로 양의 방향으로 5프레임 이동한다면 다음 채널로 이동하는 command를 return해줍니다. 반대로 음의 방향으로 5프레임 이동한다면 이전 채널로 이동하는 command를 return하게 됩니다
get_command_3_4_5_6
get_command_3_4_5_6(parts, command) 함수는 두 손을 활용해 볼륨조절과 전원을 컨트롤하는 함수입니다. 먼저 두 손을 인식하고 기준 손 혹은 반대쪽 손의 좌표가 변화하는지 인식합니다. 좌표가 변화하는 손을 기준으로 볼륨조절을 실행하게 되며, 볼륨을 조절하는 방식은 프레임 마다 diff의 값과 현재 손의 위치를 비교하여 path_flag에 증가 혹은 감소 flag값(1, 2)을 저장하고 다음으로 이전 손의 위치와 현재 손의 위치를 비교함으로써 인과적 시스템으로 손의 위치에 따라 볼륨 조절 기능을 수행하게 됩니다.
볼륨 조절의 간격은 눈 사이의 x좌표 거리를 절대값으로 측정하여 비교해 손이 움직인 거리의 절대값이 더 크다면 flag에 따라 볼륨 Up 혹은 볼륨 Down의 command를 return하게 되며, 절대값이 더 작다면 "대기"라는 command를 return하게 됩니다.
전원부는 왼쪽 혹은 오른쪽 손의 좌표가 일치하게 된다면 path_flag에 전원제어(3)flag값을 저장하며, 전원끄기/켜기 command를 return하게 됩니다.
get_command
get_command함수는 이전에 두 손으로 제어했는지, 한 손으로 제어했는지 확인하는 함수입니다. 모드 전환이 발생하면 내부의 카운트를 초기화하고, 모드 전환이 발생하지 않았다면 기존 함수를 호출해 사용하도록 설계하였습니다.
figure_out_command
figure_out_command함수에서는 프레임마다 get_parts를 통해 팔의 좌표를 갱신하고, parts.check_switch의 값이 False라면 팔이 내려갔음을 확인합니다. 확인을 마치면 제스쳐 모드 종료(8)이라는 command를 return하게 됩니다. 그리고 초기값 저장을 위해 초기 위치 지정이 안되어 있다면 (parts.init_flag의 값이 False), parts.init_positioning을 통해 초기값을 지정합니다.
마지막으로 볼륨조절의 값을 인과적으로 받아오기 위해 if command is not 0 and command is not 3 and command is not 4으로 두 손이 인식되면서 if parts.check_return() is False and parts.two_hand is False로 전원제어가 아니라면 return없이 지속적으로 roop를 실행할 수 있도록 설계하였으며, 볼륨 조절 시스템을 인과적으로 받아오기 위해 매 프레임마다 볼륨 조절을 수행했다면 command를 다시 초기화 하도록 추가하여 설계했습니다.
parts.py
get_dist
get_dist(x1, x2, y1, y2) 함수는 두 점의 x 및 y 좌표를 나타내는 x1, x2, y1 및 y2의 네 가지 인수를 사용해 2차원 평면에서 두 점 사이의 거리를 계산하는 함수입니다.
check_switch
check_switch 메소드는 제스쳐모드의 현재 상태를 확인하고 제스쳐모드가 켜져 있는지(True) 꺼져 있는지(False) 나타내는 boole 값을 반환합니다.
boole값을 이용해 변수에 직접 액세스하지 않고도 제스쳐모드가 현재 켜져 있는지 꺼져 있는지 빠르고 쉽게 확인할 수 있도록 제작했습니다.
init_positioning
init_positioning함수는 손의 초기 위치를 확인하는 함수입니다. 왼손과 오른손을 구분하여 코의 y좌표보다 크다면 self.initial_position객체에 저장되어 초기 위치를 저장합니다.
check_two_hand
check_two_hand()함수는 현재 모드 상태를 구분하는 함수입니다. 오른손과 왼손의 y좌표를 코의 y좌표와 비교하여 and연산을 통해 두 손이 코의 y좌표보다 크다면 self.two_hand 매서드에 True를 저장하고 self.two_hand값을 return합니다.
else에서는 반대로 self.two_hand의 매서드에 False를 저장하고, 값을 return합니다.
check_return
check_return함수는 손의 처음 좌표와 현재 좌표의 차이를 확인하는 함수입니다. 오른손 왼손을 구분하여 diff변수에 get_dist값을 저장합니다. diff의 값이 get_eye_dist에 정의되어있는 self.eye_dist의 값(눈 사이의 거리)보다 작다면 True를 리턴하고 아니면 False를 리턴해 손의 처음 좌표와 현재 좌표를 비교할 수 있도록 설계하였습니다.
결론
제스처 인식에 Posenet을 사용하고 TV 리모컨으로 기능하는 프로그램은 딥 러닝과 컴퓨터 비전의 혁신적인 응용 프로그램입니다. 제스처를 사용하여 TV를 제어하는 방식은 실용적인 도구이며, 프로그램의 사용 편의성은 광범위한 사용자가 액세스할 수 있도록 합니다.Beta Was this translation helpful? Give feedback.
All reactions