De acordo com as Leis 12.965/2014 e 13.709/2018, que regulam o uso da Internet e o tratamento de dados pessoais no Brasil, ao me inscrever na newsletter do portal DICAS-L, autorizo o envio de notificações por e-mail ou outros meios e declaro estar ciente e concordar com seus Termos de Uso e Política de Privacidade.

Detectando assalto na multidão com visão computacional

Colaboração: Alessandro de Oliveira Faria

Data de Publicação: 13 de dezembro de 2018

OpenPose é uma biblioteca de detecção de articulações de múltiplos humanos simultaneamente, ou seja, é capaz de identificar as articulações de várias pessoas em uma única cena em tempo real com algoritmos de detecção de esqueleto. A detecção ocorre em tempo real e é possível detectar corpo, rosto e mãos.

A tecnologia OpenPose detecta até 135 pontos no total, incluso face, mão, pé e corpo. Utilizando esta tecnologia, a etapa mais importante e com maior custo computacional referente à detecção de vértice encontra-se equacionada tecnicamente, restando apenas o trabalho de reconhecer um soco ou uma posição de assalto, calculando o ângulo formado pela abertura dos braços em relação à cabeça e à região próxima ao centro do esqueleto. Em outras palavras, detecção de comportamento.

Seguindo este mesmo princípio computacional, podemos detectar inúmeros comportamentos baseados no aprendizado de análise do posicionamento e movimentos dos vértices. Com algoritmos para detectar comportamentos, podemos utilizar o reconhecimento de um indivíduo através do caminhar.

Mão na massa

Primeiramente lembramos que a principal dependência deste projeto é a biblioteca openCV 3.X ou superior e a biblioteca CUDA da NVIDIA, devemos efetuar o download dos fontes OpenPose no repositório github com o comando a seguir:

$ git clone https://github.com/CMU-Perceptual-Computing-Lab/openpose/
Cloning into 'openpose'...
remote: Enumerating objects: 518, done.
remote: Counting objects: 100% (518/518), done.
remote: Compressing objects: 100% (350/350), done.
remote: Total 17652 (delta 283), reused 239 (delta 164), pack-reused 17134
Receiving objects: 100% (17652/17652), 81.35 MiB | 955.00 KiB/s, done.
Resolving deltas: 100% (13463/13463), done.

Após o download dos fontes, entre na pasta openopose, crie a pasta build e prepare as diretivas de compilação com o comando cmake.

cd openpose
$ mkdir build
$ cd build/
$ cmake ..

Se tudo estiver funcionando corretamente, principalmente a dependência do ambiente, teremos a seguinte saída:

-- The C compiler identification is GNU 4.8.5
— The CXX compiler identification is GNU 4.8.5
— Check for working C compiler: /usr/bin/cc
— Check for working C compiler: /usr/bin/cc -- works
— Detecting C compiler ABI info
— Detecting C compiler ABI info - done
— Detecting C compile features
— Detecting C compile features - done
— Check for working CXX compiler: /usr/bin/c++
— Check for working CXX compiler: /usr/bin/c++ -- works
— Detecting CXX compiler ABI info
— Detecting CXX compiler ABI info - done
— Detecting CXX compile features
— Detecting CXX compile features - done
— GCC detected, adding compile flags
— Looking for pthread.h
— Looking for pthread.h - found
— Looking for pthread_create
— Looking for pthread_create - not found
— Looking for pthread_create in pthreads
— Looking for pthread_create in pthreads - not found
— Looking for pthread_create in pthread
— Looking for pthread_create in pthread - found
— Found Threads: TRUE  
— Found CUDA: /usr/local/cuda-8.0 (found version "8.0") 
— Building with CUDA.
— CUDA detected: 8.0
— Found cuDNN: ver. 6.0.21 found (include: /usr/local/cuda-8.0/include, library: /usr/local/cuda-8.0/lib64/libcudnn.so)
— Automatic GPU detection failed. Building for all known architectures.
— Added CUDA NVCC flags for: sm_20 sm_21 sm_30 sm_35 sm_50 sm_52 sm_60 sm_61
— Found cuDNN: ver. 6.0.21 found (include: /usr/local/cuda-8.0/include, library: /usr/local/cuda-8.0/lib64/libcudnn.so)
— Found GFlags: /usr/include  
— Found gflags  (include: /usr/include, library: /usr/lib64/libgflags.so)
— Found Glog: /usr/include  
— Found glog    (include: /usr/include, library: /usr/lib64/libglog.so)
— Found OpenCV: / (found version "4.0.0") 
— Caffe will be downloaded from source now. NOTE: This process might take several minutes depending
        on your internet connection.
Submodule '3rdparty/caffe' (https://github.com/CMU-Perceptual-Computing-Lab/caffe.git) registered for path '../3rdparty/caffe'
Cloning into '/dados/Fontes/OSS/openpose/3rdparty/caffe'...
Submodule path '../3rdparty/caffe': checked out '9453eb00f6073ab9091f8a3a973538c7bdcb6785'
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
— Caffe will be built from source now.
— Download the models.
— Downloading BODY_25 model...
— NOTE: This process might take several minutes depending on your internet connection.
— Not downloading body (COCO) model
— Not downloading body (MPI) model
— Downloading face model...
— NOTE: This process might take several minutes depending on your internet connection.
— Downloading hand model...
— NOTE: This process might take several minutes depending on your internet connection.
— Models Downloaded.
— Configuring done
— Generating done
— Build files have been written to: /dados/Fontes/OSS/openpose/build

Após a configuração ambiental para compilação dos fontes, efetue o comando make:

$ make
Scanning dependencies of target openpose_caffe
[ 12%] Creating directories for 'openpose_caffe'
[ 25%] No download step for 'openpose_caffe'
[ 37%] No patch step for 'openpose_caffe'
[ 50%] No update step for 'openpose_caffe'
[ 62%] Performing configure step for 'openpose_caffe'
— The C compiler identification is GNU 4.8.5
— The CXX compiler identification is GNU 4.8.5
— Check for working C compiler: /usr/bin/cc
— Check for working C compiler: /usr/bin/cc -- works
— Detecting C compiler ABI info
— Detecting C compiler ABI info - done
— Detecting C compile features
— Detecting C compile features - done
— Check for working CXX compiler: /usr/bin/c++
— Check for working CXX compiler: /usr/bin/c++ -- works
— Detecting CXX compiler ABI info
— Detecting CXX compiler ABI info - done
— Detecting CXX compile features
— Detecting CXX compile features - done
— Looking for pthread.h
— Looking for pthread.h - found
— Looking for pthread_create
— Looking for pthread_create - not found
— Looking for pthread_create in pthreads
— Looking for pthread_create in pthreads - not found
— Looking for pthread_create in pthread
— Looking for pthread_create in pthread - found
— Found Threads: TRUE  
— Boost version: 1.61.0
— Found the following Boost libraries:
—   system
—   thread
—   filesystem
—   chrono
—   date_time
—   atomic
— Found GFlags: /usr/include  
— Found gflags  (include: /usr/include, library: /usr/lib64/libgflags.so)
— Found Glog: /usr/include  
— Found glog    (include: /usr/include, library: /usr/lib64/libglog.so)
— Found Protobuf: /usr/lib64/libprotobuf.so  
— Found PROTOBUF Compiler: /usr/bin/protoc
— Found HDF5: /usr/lib64/libhdf5_hl.so;/usr/lib64/libhdf5.so;/usr/lib64/libpthread.so;/usr/lib64/libz.so;/usr/lib64/libdl.so;/usr/lib64/libm.so (found version "1.8.15") 
— CUDA detected: 8.0
— Found cuDNN: ver. 6.0.21 found (include: /usr/local/cuda-8.0/include, library: /usr/local/cuda-8.0/lib64/libcudnn.so)
— Automatic GPU detection failed. Building for all known architectures.
— Added CUDA NVCC flags for: sm_20 sm_21 sm_30 sm_35 sm_50 sm_60 sm_61
— Found Atlas: /usr/include  
— Found Atlas (include: /usr/include library: /usr/lib64/atlas/libatlas.a lapack: /usr/lib64/liblapack.so
— Python interface is disabled or not all required dependencies found. Building without it...
— Found Git: /usr/bin/git (found version "2.13.7") 
— 
— ******************* Caffe Configuration Summary *******************
— General:
—   Version           :   1.0.0
—   Git               :   1.0-112-g9453eb00
—   System            :   Linux
—   C++ compiler      :   /usr/bin/c++
—   Release CXX flags :   -O3 -DNDEBUG -fPIC -Wall -Wno-sign-compare -Wno-uninitialized
—   Debug CXX flags   :   -g -fPIC -Wall -Wno-sign-compare -Wno-uninitialized
—   Build type        :   Release
— 
—   BUILD_SHARED_LIBS :   ON
—   BUILD_python      :   OFF
—   BUILD_matlab      :   OFF
—   BUILD_docs        :   OFF
—   CPU_ONLY          :   OFF
—   USE_OPENCV        :   OFF
—   USE_LEVELDB       :   OFF
—   USE_LMDB          :   OFF
—   USE_NCCL          :   OFF
—   ALLOW_LMDB_NOLOCK :   OFF
— 
— Dependencies:
—   BLAS              :   Yes (Atlas)
—   Boost             :   Yes (ver. 1.61)
—   glog              :   Yes
—   gflags            :   Yes
—   protobuf          :   Yes (ver. 3.5.0)
—   CUDA              :   Yes (ver. 8.0)
— 
— NVIDIA CUDA:
—   Target GPU(s)     :   Auto
—   GPU arch(s)       :   sm_20 sm_21 sm_30 sm_35 sm_50 sm_60 sm_61
—   cuDNN             :   Yes (ver. 6.0.21)
— 
— Install:
—   Install path      :   /dados/Fontes/OSS/openpose/build/caffe
— 

Agora, após a compilação, basta executar o comando openpose.bin presente na pasta bin/examples/openpose:

$ optirun ./build/examples/openpose/openpose.bin   --image_dir /home/cabelo/Imagens/openpose/ --write_images /home/cabelo/Imagens/openpose/save/
Starting OpenPose demo...
Configuring OpenPose...
Starting thread(s)...
Auto-detecting all available GPUs... Detected 1 GPU(s), using 1 of them starting at GPU 0.
OpenPose demo successfully finished. Total time: 18.717633 seconds.
Alessandro de Oliveira Faria é Pesquisador, Palestrante, Sócio-fundador da empresa OITI TECNOLOGIA fundada em Junho de 1996, empresa especializada em desenvolvimento de soluções com a tecnologia de Reconhecimento Facial, Consultor Biométrico, Experiência em Realidade Aumentada, Visão Computacional (contribuidor opencv), Neuro-tecnologia, Redes Neurais e Programação multi-nuclear com CPU e GPU, atua na área de tecnologia desde 1986, leva o Linux a sério desde 1998, membro da comunidade Viva O Linux com mais de 50 palestras e 100 artigos publicados, mantenedor da biblioteca open-source de vídeo captura, Embaixador, openSUSE Member e Intel Innovator.

Adicionar comentário

* Campos obrigatórios
5000
Powered by Commentics

Comentários

Nenhum comentário ainda. Seja o primeiro!


Veja a relação completa dos artigos de Alessandro de Oliveira Faria