Notice: MediaWiki has been updated. Report any rough edges to marcan@marcan.st

Getting Started/pt-br

From OpenKinect
Revision as of 05:44, 5 March 2011 by BankP (talk | contribs) (→‎Compiling: To be current in relation to the English page i.e. "build or rebuild" when items fail.)
Jump to navigationJump to search
Idioma: English  • français • italiano • português do Brasil

Por favor leia este artigo antes de começar

Esta página documenta como começar a utilizar o OpenKinect. As bibliotecas estão em processo de desenvolvimento este não será o processo final. Isto também significa que estas instruções devem estar desatualizadas para os últimos commits. Olhe para os seguintes links para mais informações:

  • O README principal do projeto OpenKinect no GitHub (não se esqueça de olhar para os arquivos readmena árvore do projeto para componentes específicos
  • A Seção Wrappers
  • A lista de e-mails do OpenKinect
  • O FAQ

Suporte

Para pedidos de suporte no canal IRC do OpenKinect ou na lista de e-mails, por favor especifique a plataforma na qual você esta utilizando, a versão do software no qual você esta tentando compilar ou instalar e informações sobre o contexto do seu problema etc. como explicado aqui.

O Adaptador

A Kinect precisa de seu próprio adaptador de energia que é independente da conexão USB para que funcione em um computador. A última versão do Xbox360 pode alimentar a Kinect diretamente mas a versão antiga requer um adaptador para este propósito. Por isso, a Kinect acompanhada ao Xbox360 não inclui o adaptador enquanto que a Kinect vendida separadamente acompanha o adaptador. O adaptador é vendido aqui. Este adaptador é necessário para utilizar a Kinect em um computador com o libfreenect.

Fakenect

Também é possível utilizar o utilitário Fakenect que é uma interface libfreenect simulador/mock para rodar os demos Kinect sem ter um sensor Kinect.

Obrigado!

Linux

Pacotes Binários

Os pacotes já compilados em RPM e DEB estão disponíveis aqui: http://livingplace.informatik.haw-hamburg.de/blog/?p=228

Por favor note que não existem udev generated devices desta maneira você precisa executar seu programa como root (utilize o sudo).

Este pacotes foram atualizados pela última vez em 19,Nov,2010

Ubuntu

Esta disponível uma Ubuntu lauchpad ppa para o Lucid(10.04) e Maverick (10.10):

https://launchpad.net/~arne-alamut/+archive/freenect

para utilizar isto, abra seu console e execute:

$ sudo add-apt-repository ppa:arne-alamut/freenect

Ressincronize a lista de pacotes do novo repositório:

$ sudo apt-get update

Depois disto você pode utilizar:

$ sudo apt-get install freenect

Isto irá instalar os seguintes pacotes libfreenect0.0, libfreenect-demos and libfreenect-dev.

Então você precisará adicionar você mesmo ao grupo 'video' deslogar e logar novamente. O pacote já inclui todas as regras necessárias para o daemon udev, desta maneira será possível aos usuários do grupo vídeo acessarem o dispositivo

$ sudo adduser NOMEUSUARIO video

não se esqueça de deslogar e logar novamente. Você não precisa reiniciar o computador, conecte sua Kinect (se ela já estava conectada, desconecte-a e conecta-a novamente).

Para começar o aplicativo demo utilize

$ freenect-glview

Você encontra todos os aplicativos demonstração começando com o prefixo freenect-

Instalação Manual no Ubuntu

Rapidamente copie e cole estas instruções para ter o funcionamento rápido e instantâneo:


sudo apt-get install git-core cmake libglut3-dev pkg-config build-essential libxmu-dev libxi-dev libusb-1.0-0-dev
git clone https://github.com/OpenKinect/libfreenect.git
cd libfreenect
mkdir build
cd build
cmake ..
make
sudo make install
sudo ldconfig /usr/local/lib64/
sudo glview

Esta deve ser a maneira mais rápida para ter a Kinect funcionando em um Ubuntu pelo menos. O próximo passo é recomendado:

sudo adduser YOURNAME video
cat << EOF >> /etc/udev/rules.d/51-kinect.rules
# ATTR{product}=="Xbox NUI Motor"
SUBSYSTEM=="usb", ATTR{idVendor}=="045e", ATTR{idProduct}=="02b0", MODE="0666"
# ATTR{product}=="Xbox NUI Audio"
SUBSYSTEM=="usb", ATTR{idVendor}=="045e", ATTR{idProduct}=="02ad", MODE="0666"
# ATTR{product}=="Xbox NUI Camera"
SUBSYSTEM=="usb", ATTR{idVendor}=="045e", ATTR{idProduct}=="02ae", MODE="0666"
EOF

Compilação Manual no linux

estas instruções precisam de mais trabalho, principalmente tiradas do README.asciidoc'

Instalando Dependências

Para compilar, você irá precisar das seguintes libs e programas instalados:

* cmake
* libusb-1.0-0
* libusb-1.0-0-dev
* pkg-config
* libglut3
* libglut3-dev

Note que os nomes dos pacotes acima são orientados para o Ubuntu/Debian. Para uma instalação de não desenvolvedor do RedHat/Fedora utilizando o comando yum/rpms, o seguinte comando deve instalar todos os pacotes necessários para recuperar, compilar e executar o demo glview:

$ yum install git cmake gcc gcc-c++ libusb1 libusb1-devel libXi libXi-devel libXmu libXmu-devel freeglut freeglut-devel

Usuários APT: (Funciona no Ubuntu 10.10)

$ sudo apt-get install cmake libglut3-dev pkg-config build-essential libxmu-dev libxi-dev libusb-1.0-0-dev

Clonando o repositório

$ git clone https://github.com/OpenKinect/libfreenect.git
$ cd libfreenect

Cmake

$ mkdir build
$ cd build
$ cmake ..
$ make
$ sudo make install
$ sudo ldconfig /usr/local/lib64/

Erros

Caso você cai no seguinte erro do cmake:

$ CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
$ Please set them or make sure they are set and tested correctly in the CMake files:
$ GLUT_Xi_LIBRARY (ADVANCED)
$    linked by target "glview" in directory /home/user/libfreenect/examples
$ GLUT_Xmu_LIBRARY (ADVANCED)
$    linked by target "glview" in directory /home/user/libfreenect/examples

Então você deve instalar as seguintes libs libxi-dev and libxmu-dev/libxmu-headers Se você estive utilizando o ubuntu 10.04, entre com o comando: sudo apt-get install libusb-1.0-0-dev libxmu-dev libxi-dev

No caso do glview dar um erro de shared library/bibliotecas compartilhadas:

$ glview 
glview: error while loading shared libraries: libfreenect.so.0.0: cannot open shared object file: No such file or directory

Você precisa atualizar o cache do ldconfig:

$ sudo ldconfig /usr/local/lib64/

é claro que isto depende se você tem as libs compartilhadas instaladas.

Python

Para compilar os wrappers para Python você precisará do pacote "python-dev" e o cython. O pacote cython já incluído no Ubuntu 10.10 parece estar quebrado (veja aqui), pegue ele aqui ou tente

 $ easy_install cython

Para mais informações sobre os wrappers veja nesta página.

Utilizando como um usuário normal

Para ser capaz de acessar a Kinect você precisa adicionar você para o grupo do video e mudar as permissões para o dispositivo criado.

crie um arquivo em: /etc/udev/rules.d/66-kinect.rules

#Rules for Kinect ####################################################
SYSFS{idVendor}=="045e", SYSFS{idProduct}=="02ae", MODE="0660",GROUP="video"
SYSFS{idVendor}=="045e", SYSFS{idProduct}=="02ad", MODE="0660",GROUP="video"
SYSFS{idVendor}=="045e", SYSFS{idProduct}=="02b0", MODE="0660",GROUP="video"
### END #############################################################

adicione você no grupo video:

$ sudo adduser YOURNAME video

Testando a Kinect

Você precisa fazer isto como root (ou use sudo) caso não tenha seguido os passo do "Utilizando como um usuário normal".

$ bin/glview

ou

$ sudo bin/glview

OS X

Você precisa instalar (ou pelo menos os pré-requisitos) através do gerenciador de pacotes. Se você ainda não esta utilizando o macports ou fink, tente Homebrew já que ele é um grande pacote criado com todas estas ferramentas.

MacPorts

Atualmente as versões do MacPorts precisam suportar diferentes versões da libusb. Nós adicionamos um port especial libusb-devel que compila a versão libusb com um patch requerido para a Kinect.

Depois de instalar o MacPorts, execute os comandos:

 sudo port install git-core
 sudo port install libtool
 sudo port install libusb-devel

Então mude para um diretório de trabalho e esteja pronto para:

git clone https://github.com/OpenKinect/libfreenect.git

e continue conforme a seção Manual Compile no OSX. A libusb encontrada pelo cmake será a correta' e já com o patch, simplificante enormemente o processo de compilação!

Homebrew

If you dont have Homebrew already, it is quite simple to install.

Note: Even if you already have homebrew, make sure to update your formulas (run `brew update`), before trying to install libfreenect as there has been a lot of bugfixing to cmake lately.

Get the formulas

Since the project is still so much in flux the packages are not yet in the official homebrew directory, so you will need to manually fetch them:

cd /usr/local/Library/Formula
curl --insecure -O "https://github.com/OpenKinect/libfreenect/raw/master/platform/osx/homebrew/libfreenect.rb"
curl --insecure -O "https://github.com/OpenKinect/libfreenect/raw/master/platform/osx/homebrew/libusb-freenect.rb"

Install

brew install libfreenect

And thats it, you are done! A copy of glview demo should now be in your PATH so you can simply run:

glview

to confirm everything worked out ok.

Manual Build under OSX

Prerequisites:

Next create fetch the OpenKinect repository and libusb:

git clone https://github.com/OpenKinect/libfreenect.git
git clone git://git.libusb.org/libusb.git

You don't need to fetch and patch libusb if you already installed libusb-devel via MacPorts (see above)! If you cloned libusb via github you will need to patch it for OpenKinect like so:

cd libusb
./autogen.sh
patch -p1 < ../libfreenect/platform/osx/libusb-osx-kinect.diff
./configure LDFLAGS='-framework IOKit -framework CoreFoundation'
make
sudo make install

and configure OpenKinect:

cd ../libfreenect/
mkdir build
cd build
ccmake ..

Don't worry if it shows you an 'Empty Cache' at startup. Now press 'c' in ccmake to configure it. If you already installed libusb via MacPorts or Homebrew, it will work fine. Otherwise it will likely fail, because it cannot find libusb. Press 'e' to exit help and manually edit the path to libusb in the following screen to point to /usr/local/include/libusb-1.0/ and continue.

When you're done, build OpenKinect:

cmake ..
make

If you want to build OpenKinect as an Xcode project, instead do:

cmake -G Xcode ..
make

And you're done! There now should be a program called 'glview' in libfreenect/build/bin. Connect your Kinect and start it! If you run into 'ld: warning: in /usr/local/lib/libusb-1.0.dylib, missing required architecture x86_64' when using make, you have to correct the paths with cmake: They have to point to /opt ... when libusb was installed via MacPorts.

To have the files globally available on your Mac and to use them with your own projects, you may install them:

sudo make install

Parallel usage with pyusb

If you also want to use pyusb to play with the Kinect, you will need libusb-1.0.8 (it seems). Install it via homebrew and then define the _lib variable before finding the usb device:

from ctypes import *
import usb.core
import usb.utils

_lib = CDLL('/usr/local/Cellar/libusb/1.0.8/lib/libusb-1.0.dylib') # That's the location homebrew puts the libusb libraries
dev = usb.core.find(idVendor=0x045e, idProduct=0x02B0)

Windows

If you are looking for a showcase of the project's features before compiling, you could take a look at this precompiled demo (source is available as well) which uses libfreenect and opencv.

Manual build from source

Introduction

Building from source shouldn't require any specific expertise but may yet be challenging for some. This introduction will serve to give those who need it a bit of background as to what we're trying to do here. To summarize, you will be downloading the latest libfreenect source and separate dependencies. The dependencies will be used twofold. First, you will copy .dll files to your system where they can be accessed. Secondly, you will link .lib and header files to the source code using the cmake-gui program in order to configure the project and generate the makefiles required for compiling. Finally, you will bring the configured project to your integrated development environment (ex. Visual Studio 2010) for compiling proper or to start your own development. So you should understand from this that your system needs some libraries to run the project demos just like any other piece of software usually does (and .dll files are used for this) and that before this can happen the project itself needs links to libraries and headers to build properly. Note that the resulting compiled libfreenect is itself a dll library which your computer will need to access in order to run the glview.exe demo for example. All of this should become quite clear as you go through the steps.

Getting the source files

There are 2 ways to get the latest source:

  1. Go to the OpenKinect project github, select the branch you want (master or unstable for instance - see below) and click the "Download" button (then extract the files to a convenient location) or
  2. Use Git to create and keep an up to date project folder and access any branch locally:

Using Git

  • Download and install Git with these settings:
    • Accept the license etc.
    • Choose the level of shell integration you want
    • Choose "Run git from the Windows Command prompt"
    • Choose "Check out WIndows style, commit Unix-style line endings"
  • Open a Command Prompt, cd to the directory where you want the source folder (/libfreenect) created and type:
$ git clone https://github.com/OpenKinect/libfreenect.git //downloads the project, creates local master
$ cd libfreenect                                            //cd to source directory
$ git branch --track unstable origin/unstable        //creates a local unstable branch for remote unstable
$ git checkout master                                //check out the master or unstable branch
$ or
$ git checkout unstable
$ git pull                                           //updates the contents of the selected branch
  • The contents of the libfreenect folder will interactively change as you checkout a specific branch (magic!) so you don't need to search for a specific "branch" folder inside the libfreenect directory. Just checkout the branch you want to configure and proceed using the libfreenect folder as source in cmake. This setup allows you to easily switch between the master and unstable branch, update the source files and then configure the branch you want to build.
  • The "git branch" command will show you the different branches (here master and unstable) and which one is currently selected. You can also view the development logs for the branch you're checking out with the "git log" command (use shift-Q to exit the log).

Master vs. unstable branch

If you plan on changing libfreenect, writing wrappers, or trying the latest developments you might want to check out the unstable branch. Unstable has the latest commits that have not been fully tested yet. Otherwise just try the 'master' branch.

  • Take note that the master and unstable branches were synced on Jan. 6, 2011; see this update for more information.
  • You may also look into some further performance updates that have not yet been integrated to the project; see this post for further information.

After you have the source files, you should download the dependencies required to configure and build the library and then install the hardware driver...

Dependencies

For each required dependency, first download and install the libraries (.dll) on your system and then identify the paths to the libraries (.lib or .a) and header (.h) files which you will need later on to configure the source project using cmake:

Dependency Install Library/includes to be used with cmake (see this printscreen)
libusb-win32 - download and extract the latest libusb-win32-bin-x.x.x.x.zip This will be taken care of when we install the driver in the next section The /lib and /include folders contain the libraries and header files required to configure the project; depending on the compiler you choose, you may have to specify a different library file:
  • For instance, to configure for MS Visual Studio 2010, use /lib/msvc/libusb.lib or if you plan to use mingw, use /lib/gcc/libusb.a as the libusb library path in cmake (LIBUSB_1_LIBRARY)
  • Select the path to the libusb header folder /include as libusb include path in cmake (LIBUSB_1_INCLUDE_DIR)

For more info see the libusb-win32 readme and their wiki

pthreads-win32 - download and extract the latest pthreads-w32-x-x-x-release.exe Find the /lib folder and copy the appropriate .dll library to /windows or /windows/system32 (see Library/includes to the right to figure out which one to use) The /lib and /include contain the libraries and header files required to configure the project; depending on the compiler you choose, you may have to specify a different library file:
  • For instance, to configure for MS Visual Studio 2010, use /lib/pthreadVC2.lib or if you plan to use mingw, use /lib/pthreadGC2.a as the pthread library path in cmake (THREADS_PTHREADS_WIN32_LIBRARY)
  • In both cases you will need to install the corresponding library .dll file to /windows/system32 i.e. phtreadVC2.dll or pthreadGC2.dll
  • Select the path to the pthread header folder /include as pthread include path in cmake (THREADS_PTHREADS_INCLUDE_DIR)

For more info see the pthreads-win32 readme and their FAQ

Glut - download and extract the latest glut-x.x.x-bin.zip Find the glut32.dll file and copy it to /windows/system or any directory included in your PATH system variable (see this explanation)
  • With MSVC, you should copy the glut.h header file to the /include/GL folder and the glut32.lib library to the /lib folder of your VC tree(for instance /Program Files/Microsoft Visual Studio 10.0/VC/) - if the GL folder is not there, create it and put the glut.h file there. If you built glut from source, the files should already be there.
  • In cmake-gui, supply the path to the header up to the /include folder (NOT ../include/GL) and the path to the library itself (../lib/glut32.lib) in cmake (GLUT_INCLUDE_DIR and GLUT_glut_LIBRARY respectively)

For more info see the glut readme

Driver installation

There are two parts to libfreenect -- the low-level libusb-based device driver and libfreenect itself, the library that talks to the driver. You only need to install the driver once.

Windows 7: step-by-step walkthrough (should also work with Windows XP!)

  • Plug in your Kinect. Windows will warn that no device driver was found for the plugged device (the LED of Kinect will not turn on). If Windows presents a dialog asking to search for drivers, simply cancel it.
  • Open the Device Manager: Start >> Control Panel >> System and Security >> System >> Device Manager
  • A device called "Xbox NUI Motor" should be somewhere there (most probably be under "Other devices") with a small yellow warning symbol "!" on top of its icon. Right click on it, and select "Update Driver Software...", then click on "Browse my computer for driver software".
  • "Browse" and select the folder where the "XBox_NUI_Motor.inf" is located (/platform/windows/inf inside your libfreenect source folder). Click "Next" and if warned by Windows that a non-certified driver is about to be installed, just order it to install it anyway.
  • After that, the Kinect LED should start blinking green. Now there will be two additional devices in the Device Manager list: "Xbox NUI Camera" and "Xbox NUI Audio". Repeat the above instructions for them as well.

You are now ready to configure libfreenect before building...

Configuring with cmake-gui

Follow these steps to configure libfreenect for compiling:

  1. Download Cmake (Cross-Platform Make) and make sure you have a working C compiler (Visual Studio 2010 or MinGW)
  2. Launch Cmake-GUI and select your /libfreenect folder as source, select an output folder, check the "advanced" and "grouped" checkboxes to display more variables and categorize them and then click on the "Configure" button
  3. Select the C compiler you want to use
  4. Select the BUILD options you want, taking into consideration the following:
    1. For now only select the EXAMPLES and C_SYNC options in BUILD. The other build options such as FAKENECT have not been updated for Visual Studio yet
    2. But take a look at the following notes if you're interested in compiling the PYTHON wrapper
  5. Unresolved dependencies will show up as red in the CMake GUI. Supply the missing paths to the dependencies by following these guidelines, and click the "Configure" button again:
    1. The *_LIBRARY variables need to point to actual .lib files not a folder
    2. INCLUDE variables need to point to the appropriate include directories
  6. When all errors have been resolved, click on the "Generate" button to create the makefiles for your compiler.

Compiling

Now that the project is configured, open libfreenect.sln from your output folder and build it with Visual Studio. Then look for your compiled files in /bin and /lib

  • The freenect libraries in /lib are compiled but not installed at this point. To use them you should:
    • Add the path to the /lib folder to your system PATH environment variable or
    • Copy the libraries to a folder already in the system PATH like /windows/system32 or
    • Copy libraries to the folder of the program you want to run
  • If some items fail to compile the first time, simply right-click on the solution again and select "Build" or "Rebuild" to see if the missing items compile
  • If you're having issues compiling check out the readme in the /libfreenect/platform/windows folder for more information.

Testing

To do a quick test run /bin/glview.exe

  • It's also a good idea to check the wrappers section and the mailing list for more ideas and solutions...

User contributions