mediapipe holistic 새로고침 하기

pixgram·2023년 11월 15일

mediapipe holistic을 이용해서 수화앱을 만들고 있는데, 모바일에서 카메라를 선택할때 반응이 느려지는 현상이 있어 살펴보니 holistic 객체가 새로고침되지 않아서 문제가 발생되었다.

api를 살펴보니 reset()이라는것이 있어 사용해 보았지만, 왜 안되는지는 모르겠으나 동작하지 않았다.

holistic.reset()

소스를 까 보았더니 close라고 해당 객체를 삭제 시키는 기능이 있어서 이 기능을 사용해 객체를 없애고 새로 객체를 만들기로 하였다.

await holistic.close();

video.then(stream => {
    videoElement.srcObject = stream;

    holistic = new Holistic({
      locateFile: (file) => {
          return `@mediapipe/holistic/${file}`;
        },
    });

    holistic.setOptions({
      selfieMode: true,
      modelComplexity: 1,
      smoothLandmarks: true,
      enableSegmentation: false,
      smoothSegmentation: true,
      minDetectionConfidence: 0.5,
      minTrackingConfidence: 0.5,
    });

    holistic.onResults(onResults);
  })

카메라가 바뀌었을 때 holistic 객체를 close해주고 새로 만들어주니 카메라 교환시 느려지는 현상이 없어졌다.

참고로 카메라의 리스트와 해당 카메라는 아래와 같은 방법으로 가져올 수 있다.

navigator.mediaDevices.enumerateDevices() //사용할 수 있는 디바이스의 리스트 가져오기
navigator.mediaDevices.getUserMedia({video: {facingMode}}) //카메라 사용하기(front or back)
profile
Interactive Front-end Developer and WebGL Artist

0개의 댓글