고급 예제

다양한 도구들을 가지고 마음껏 응용해보세요.

Leapmotion

2016-07-05 14:46:04

개요

 

 

예전에 립모션(Leapmotion)에 대해 소개글을 작성한 적이 있었는데요~!

 

립모션 사용해보기(http://kocoafab.cc/tutorial/view/511)

 

 

 

 

 

 

립모션은 소개에서 말씀드렸듯이 손동작을 인식할 수 있는 장치입니다.

 

립모션의 크기는 작은 아이팟크기 정도이기만 8입방 피트(cubic feet)의 3차원 공간을 매우 정확하게 읽어냅니다.

마이크로소프트의 키넥트(Kinect)와 비슷한 원리(색상을 구분하는 RGB카메라와 깊이를 구분하는 IR카메라로 구성)를 가졌지만 키넥트보다 200배 높은 감도를 지니고 있고 100분의 1밀리미터의 움직임까지 감지한다고 합니다.

 

제스쳐 센서와 같이 손동작을 인식할 수 있기 때문에 기존에 프로그래밍만을 가지고 해결할 수 없는 문제나 접근할 수 없었던 문제들을 다른 차원에서 해결할 수 있게 도와줍니다.

 

<립모션의 손동작 인식>

 

 

 

아두이노와 립모션을 연동하기 위해서는 중간에 두 장치를 연결하는 툴이 필요한데 다양한 툴이 활용이 가능하지만 이번 글에서는 사용하기 쉬운 프로세싱(Processing)을 활용해 보겠습니다.

 

 

 

 

 

동영상

 

 

 

 

필요한 부품 목록

 

 

No 부품명 수량 상세 설명
1 오렌지 보드 1 아두이노 UNO 호환 보드
2 LED 5  
3 저항 5 330옴
4 브레드 보드 1  
5 점퍼 케이블 6  

 

오렌지 보드 LED 저항 브레드 보드 점퍼 케이블


 

 

하드웨어 making

 

브레드 보드

 

 

 

 

전자 회로도

 

 

 

 

 

소프트웨어 coding

 

 

아두이노 코드

void setup() {
  for (int i = 8; i < 13; i++) {
    pinMode(i, OUTPUT);
  }
  Serial.begin(9600);
}

void loop() {
  if (Serial.available()) {
    char b = Serial.read();
    if (b == '0') {
      digitalWrite(8, LOW);
      digitalWrite(9, LOW);
      digitalWrite(10, LOW);
      digitalWrite(11, LOW);
      digitalWrite(12, LOW);
    }
    else if (b == '1') {
      digitalWrite(8, HIGH);
      digitalWrite(9, LOW);
      digitalWrite(10, LOW);
      digitalWrite(11, LOW);
      digitalWrite(12, LOW);
    }
    else if (b == '2') {
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, LOW);
      digitalWrite(11, LOW);
      digitalWrite(12, LOW);
    }
    else if (b == '3') {
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, HIGH);
      digitalWrite(11, LOW);
      digitalWrite(12, LOW);
    }
    else if (b == '4') {
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, HIGH);
      digitalWrite(11, HIGH);
      digitalWrite(12, LOW);
    }
    else if (b == '5') {
      digitalWrite(8, HIGH);
      digitalWrite(9, HIGH);
      digitalWrite(10, HIGH);
      digitalWrite(11, HIGH);
      digitalWrite(12, HIGH);
    }
  }
}

 

 

 

 

 

프로세싱 코드

/*

 Leap Motion library for Processing.
 Copyright (c) 2012-2015 held jointly by the individual authors.
 
 This file is part of Leap Motion library for Processing.
 
 Leap Motion library for Processing is free software: you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 Leap Motion library for Processing is distributed in the hope that it will be
 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with Leap Motion library for Processing.  If not, see
 <http://www.gnu.org/licenses/>.
 
 */
import com.leapmotion.leap.Controller;
import com.leapmotion.leap.Finger;
import com.leapmotion.leap.Frame;
import com.leapmotion.leap.Hand;
import com.leapmotion.leap.processing.LeapMotion;
import processing.serial.*;


Serial port;

int fingers = 0;
LeapMotion leapMotion;

void setup()
{
  size(640, 480);
  background(20);
  frameRate(60);
  textAlign(CENTER);

  leapMotion = new LeapMotion(this);

  println("Available serial ports:");
  println(Serial.list());
  port = new Serial(this, Serial.list()[1], 9600);
}

void draw()
{
  fill(20);
  rect(0, 0, width, height);

  fill(0, 255, 255);
  textSize(3 * height / 5.0);
  text(String.valueOf(fingers), width / 2.0, 6 * height / 9.0);
  port.write(String.valueOf(fingers));
  delay(100);
}

void onFrame(final Controller controller)
{
  fingers = countExtendedFingers(controller);
}

int countExtendedFingers(final Controller controller)
{
  int fingers = 0;
  if (controller.isConnected())
  {
    Frame frame = controller.frame();
    if (!frame.hands().isEmpty())
    {
      for (Hand hand : frame.hands())
      {
        int extended = 0;
        for (Finger finger : hand.fingers())
        {
          if (finger.isExtended())
          {
            extended++;
          }
        }
        fingers = Math.max(fingers, extended);
      }
    }
  }
  return fingers;
}

 

 

 

립모션을 프로세싱에서 사용하기 위해서는 라이브러리의 설치가 필요합니다.

 

Processing3 기준으로 설명드리면 파일 - 예제를 클릭하면 아래와 같은 창을 볼 수 있습니다.

Add examples를 클릭합니다.

 

 

 

 

아래와 같은 화면을 볼 수 있습니다. 

Libraries를 클릭한 뒤 leapmotion을 검색하게되면 leapmotion을 사용할 수 있게 도와주는 라이브러리가 나옵니다.

그 중에서 Michael Heuer의 라이브러리를 클릭하여 Install합니다.

 

 

 

 

인스톨이 끝났다면 프로세싱을 완전히 끄고 다시 실행한 다음 예제를 실행시킵니다.

제대로 설치가 되었다면 아래와 같이 Contribute Libraries가 생기면서 그 하위 폴더에 Leapmotion이 생기는 것을 볼 수 있습니다.

 

 

 

이번 글에서 사용한 프로세싱의 코드는 립모션 예제 파일중 leap_finger_example을 응용하였으며 다른 예제파일을 실행 할 경우 다른 방법으로도 구현해 볼 수 있습니다.

 

kocoafabeditor

항상 진취적이고, 새로운 것을 추구하는 코코아팹 에디터입니다!

leapmotion, 립모션, 아두이노, 오렌지보드

밍디 2016-08-20 00:13:51

아두이노와 프로세싱 코드를 적고 립모션을 컴퓨터에 연결하고 코드를 업로드 외에 다른 설정이 필요한가요? 그대로 해봤는데 숫자가 안바뀌네요 ㅠ

밍디 2016-08-20 00:13:58

아두이노와 프로세싱 코드를 적고 립모션을 컴퓨터에 연결하고 코드를 업로드 외에 다른 설정이 필요한가요? 그대로 해봤는데 숫자가 안바뀌네요 ㅠ

수박쨈 2016-08-22 11:14:01

프로세싱에 보시면 아래와 같은 코드가 있습니다.

port = new Serial(this, Serial.list()[1], 9600);

여기서 Serial.list()[1]은 포트 중에 2번째 포트를 선택한다는 말인데
저같은 경우는 COM1, COM4 이렇게 있기 때문에 COM4를 선택하기 위해서 2번째 포트를 선택했습니다.

만약에 포트가 아두이노 연결 하나밖에 없다면 Serial.list()[0]으로 작성하여 업로드 시켜보세요.

문경록 2017-08-07 11:34:39

프로세싱에 라이브러리가 없어졌으면 어떻게 하나요 ㅠㅠ

김준섭 2018-04-01 14:44:30

오오 설마 했는데 이런 게 있네요 감사합니다.

김호놀 2018-05-08 13:31:28

프로세싱에 라이브러리가 사라졌는데, 어찌해야하나요???

윤물은모르게 2018-05-22 03:38:27

프로세싱에 라이브러리 사라진거 해결하신분 계신가요??

김재현 2018-11-20 12:15:17

가위바위보를 실현시키려고합니다.
미카엘 파일이 있어여되는데 파일이 없네요 어디서 다운 받습니까?

kocoafabeditor 2018-11-28 10:06:37

https://github.com/heuermh/leap-motion-processing

kocoafabeditor 2018-11-28 10:08:41

https://randomflik.blogspot.com/2016/12/blog-post_12.html

jun98 2022-10-20 12:11:29

Michael Heuerd님의 라이브러리가 없는데 찾는 방법이 있나요?