안녕하세요 슐리반입니다.
unity 에서 openpose를 이용하려는데 외국에서도 많이들 물어보더라구요
그래서 이번엔 한글판과 영문판으로 글을 작성해보려고 합니다.
1. 깃허브에서 유니티 전용 openpose를 다운로드 한 후 압축을 풉니다.
압축 풀때 저는 C드라이브에 Unity 폴더만 만들어서 압축 풀었어요
https://github.com/CMU-Perceptual-Computing-Lab/openpose_unity_plugin
GitHub - CMU-Perceptual-Computing-Lab/openpose_unity_plugin: OpenPose's Unity Plugin for Unity users
OpenPose's Unity Plugin for Unity users. Contribute to CMU-Perceptual-Computing-Lab/openpose_unity_plugin development by creating an account on GitHub.
github.com
2. 유니티 허브에서 2018.4 버전을 다운로드 받은 후, 유니티 openpose 파일을 연다.
2-1. 첫번째 링크 들어가면 이 부분이 있고 doc/installation.md를 클릭해보시면 설치 방법이 나와있어요

하지만 전 여기서 문제가 생기고 말았답니다


여기서 세번째 영역 보시면 Run getModels.bat를 누르면 모델이 다운로드 된다는데 전 로딩을 하다가 Error가 뜨는거예요
이때부터 영어든 한글이든 폭풍 구글링을 해본 결과,,,(블로그 쓰게 된 계기도 이거임)
3. 모델 폴더는 코로나 때문에 웹사이트 접속이 안된다 해서 여기서 다운받았습니다.
친절하게도 댓글에 남겨져있었어요 정말 찾느라 시간이 꽤 걸렸지만,,,
https://github.com/CMU-Perceptual-Computing-Lab/openpose/issues/1602
Unable to fetch/download models · Issue #1602 · CMU-Perceptual-Computing-Lab/openpose
Issue Summary Unable to fetch/download models Executed Command (if any) models\getModels.bat OpenPose Output (if any) Type of Issue Compilation/installation error Execution error Your System Config...
github.com
하단에 내리면 이렇게 다운로드 링크까지 있습니다
G Drive version:
Models: https://drive.google.com/file/d/1QCSxJZpnWvM00hx49CJ2zky7PWGzpcEh
models.zip
drive.google.com
4. 다운 받은 모델 폴더를 유니티 openpose 폴더 안에다가 압축 풀기
이렇게 까지하면 준비 완료입니다!
이제 유니티 안에서 할 일이에요
1. openpose 오브젝트 클릭한 다음, inspector 창에서 Input type을 확인해줍니다.
(웹캠이 잘 작동 되는지 확인하기 위해서 웹캠 먼저 해줄게요 -> 선택사항)


2. Input type을 Webcam으로 해주기
3. 컴퓨터와 웹캠이 연결 되었는지 확인해보기 (저는 USB만 꽂으면 연결되는 다이소 5000원 웹캠 사용했어요)
하지만 문제 발생!!!
OP_Error: Error occurred on a thread. OpenPose closed all its threads and then propagated the error to the main thread. Error description: Caffe trained model file not found: C:\Unity\openpose_unity_plugin-master\OpenPosePlugin\Assets\StreamingAssets\models\pose/body_25/pose_iter_584000.caffemodel. Possible causes: 1. Not downloading the OpenPose trained models. 2. Not running OpenPose from the same directory where the model folder is located. 3. Using paths with spaces
해당 오류가 떠서 또 폭풍 구글링 결과!
openpose/doc/installation/0_index.md at master · CMU-Perceptual-Computing-Lab/openpose
OpenPose: Real-time multi-person keypoint detection library for body, face, hands, and foot estimation - CMU-Perceptual-Computing-Lab/openpose
github.com

사진 속 1번을 보시면 아시겠지만 openpose.sln을 빌드해줘야했어요
4. 그래서 폴더로 가서(아래사진 참고) 밑에서 두번째에 있는 OpenPosePlugin.snl 을 열고, ctrl+F5 눌러서 빌드를 해줍니다.

그리고 다시 유니티에서 Play를 해주니 웹캠이 인식이 잘 되더라구요

(참고로 webcam으로 설정시 producer string을 -1로 해주어야 오류 안납니다)
다음으론 이제 비디오!!!
1. 먼저 openpose를 이용할 비디오를 Asset > StreamingAssets 폴더 안에 넣어줍니다.

2. 그리고 Input type을 video로 변경하고, Producer String에다가 영상의 경로를 넣어줄거예요
영상의 경로를 아는 법은 영상폴더를 오른쪽 마우스 클릭하면 Copy Path를 해줄 수 있습니다.
이걸 누르면 해당 영상의 경로가 자동으로 복사가 돼요

그리고 Producer String에 해당 영상의 경로를 붙여넣기 해줍니다.

그리고 실행하면 완료!! (참고로 OpenPosePlugin.snl 은 계속 빌드되고 있는 상태여야 해요!)

그럼 이렇게 영상까지도 잘 보이는 걸 확인하실 수 있습니다!!
사실 비디오 경로 어디에 넣나 진짜 코드도 보고 이것저것 봤는데 너무 간단했어요 ㅋㅋ
다른 분들은 문제 없이 잘 실행되시길 바라면서 글 마칩니다
도움이 되셨거나 유익했다면 좋아요와 댓글 부탁드리고 질문이나 피드백도 언제든 환영입니다
감사합니다!
'개발 > Unity' 카테고리의 다른 글
[Unity] Visual Studio와 Unity 연결하는 방법 (5) | 2021.04.13 |
---|---|
[Unity] 2차원 배열 inspector 창에서 보여주기 (2) | 2020.08.19 |
[Unity] 유니티 두 손가락 터치 드래그하여 카메라 이동 구현하기 (2) | 2020.07.29 |
[Unity] 알아두면 유용한 Mathf 클래스 함수 정리 (1) | 2020.07.29 |
[Unity] 안드로이드 APK 빌드하는 방법(ver.2019.2) (7) | 2020.07.29 |