Skip to content

Commit

Permalink
Merge pull request #56 from VitorCarvalho67/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
VitorCarvalho67 authored Mar 26, 2024
2 parents e1c98ae + 6e3a8e8 commit 536b196
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 9 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
venv/
src/collector/
bin/venv
dist/
build/
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@

# Barium (HMI)

[![GitHub license](https://img.shields.io/github/license/vitorcarvalho67/Barium)](vitorcarvalho67/Barium/blob/master/LICENSE) ![GitHub stars](https://img.shields.io/github/stars/vitorcarvalho67/Barium) ![GitHub stars](https://img.shields.io/github/languages/count/vitorcarvalho67/Barium) ![GitHub stars](https://img.shields.io/github/languages/top/vitorcarvalho67/Barium) ![GitHub stars](https://img.shields.io/github/repo-size/vitorcarvalho67/Barium) ![GitHub stars](https://img.shields.io/github/languages/code-size/vitorcarvalho67/Barium)
[![GitHub license](https://img.shields.io/github/license/vitorcarvalho67/Barium)](vitorcarvalho67/Barium/blob/master/LICENSE)
![GitHub stars](https://img.shields.io/github/stars/vitorcarvalho67/Barium)
![GitHub language](https://img.shields.io/github/languages/top/vitorcarvalho67/Barium)
![GitHub last commit](https://img.shields.io/github/last-commit/vitorcarvalho67/Barium)
![GitHub repo size](https://img.shields.io/github/repo-size/vitorcarvalho67/Barium)
![GitHub contributors](https://img.shields.io/github/contributors/vitorcarvalho67/Barium)

An innovative software that utilizes neural networks, machine learning, and deep learning for tracking body movements, such as hands, enabling advanced interactions with the operating system, including predefined actions and a virtual mouse. Additionally, the project employs 4D neural network training techniques, where time is one of the dimensions, opening up revolutionary possibilities in various technology fields

Expand Down
8 changes: 6 additions & 2 deletions README_es.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@

# Barium Interfaz Hombre-Máquina (HMI)

[![GitHub license](https://img.shields.io/github/license/vitorcarvalho67/Barium)](vitorcarvalho67/Barium/blob/master/LICENSE) ![GitHub stars](https://img.shields.io/github/stars/vitorcarvalho67/Barium) ![GitHub stars](https://img.shields.io/github/languages/count/vitorcarvalho67/Barium) ![GitHub stars](https://img.shields.io/github/languages/top/vitorcarvalho67/Barium) ![GitHub stars](https://img.shields.io/github/repo-size/vitorcarvalho67/Barium) ![GitHub stars](https://img.shields.io/github/languages/code-size/vitorcarvalho67/Barium)

[![GitHub license](https://img.shields.io/github/license/vitorcarvalho67/Barium)](vitorcarvalho67/Barium/blob/master/LICENSE)
![GitHub stars](https://img.shields.io/github/stars/vitorcarvalho67/Barium)
![GitHub language](https://img.shields.io/github/languages/top/vitorcarvalho67/Barium)
![GitHub last commit](https://img.shields.io/github/last-commit/vitorcarvalho67/Barium)
![GitHub repo size](https://img.shields.io/github/repo-size/vitorcarvalho67/Barium)
![GitHub contributors](https://img.shields.io/github/contributors/vitorcarvalho67/Barium)

Un innovador software que utiliza redes neuronales, aprendizaje automático y aprendizaje profundo para el seguimiento de movimientos corporales, como las manos, permitiendo interacciones avanzadas con el sistema operativo, incluyendo acciones predefinidas y un ratón virtual. Además, el proyecto emplea técnicas de entrenamiento de redes neuronales 4D, donde el tiempo es una de las dimensiones, abriendo posibilidades revolucionarias en diversos campos tecnológicos.

Expand Down
8 changes: 6 additions & 2 deletions README_ko.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
</p>
</h4>


<p align="center">
<img src="https://github.com/VitorCarvalho67/Barium/assets/102667323/c3067279-4aee-4b25-851b-8ebe5fe9449d" />
</p>

# Barium 인간-기계 인터페이스 (HMI)

[![GitHub license](https://img.shields.io/github/license/vitorcarvalho67/Barium)](vitorcarvalho67/Barium/blob/master/LICENSE) ![GitHub stars](https://img.shields.io/github/stars/vitorcarvalho67/Barium) ![GitHub stars](https://img.shields.io/github/languages/count/vitorcarvalho67/Barium) ![GitHub stars](https://img.shields.io/github/languages/top/vitorcarvalho67/Barium) ![GitHub stars](https://img.shields.io/github/repo-size/vitorcarvalho67/Barium) ![GitHub stars](https://img.shields.io/github/languages/code-size/vitorcarvalho67/Barium)
[![GitHub license](https://img.shields.io/github/license/vitorcarvalho67/Barium)](vitorcarvalho67/Barium/blob/master/LICENSE)
![GitHub stars](https://img.shields.io/github/stars/vitorcarvalho67/Barium)
![GitHub language](https://img.shields.io/github/languages/top/vitorcarvalho67/Barium)
![GitHub last commit](https://img.shields.io/github/last-commit/vitorcarvalho67/Barium)
![GitHub repo size](https://img.shields.io/github/repo-size/vitorcarvalho67/Barium)
![GitHub contributors](https://img.shields.io/github/contributors/vitorcarvalho67/Barium)

신경망, 기계 학습 및 딥러닝을 활용하여 손과 같은 신체 움직임을 추적하고, 운영 체제와의 고급 상호 작용을 가능하게 하는 혁신적인 소프트웨어입니다. 또한, 이 프로젝트는 시간이 하나의 차원인 4D 신경망 훈련 기술을 사용하여 다양한 기술 분야에서 혁명적인 가능성을 엽니다.

Expand Down
11 changes: 8 additions & 3 deletions README_pt-br.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@
<img src="https://github.com/VitorCarvalho67/Barium/assets/102667323/c3067279-4aee-4b25-851b-8ebe5fe9449d" />
</p>

# Barium (HMI)

[![GitHub license](https://img.shields.io/github/license/vitorcarvalho67/Barium)](vitorcarvalho67/Barium/blob/master/LICENSE) ![GitHub stars](https://img.shields.io/github/stars/vitorcarvalho67/Barium) ![GitHub stars](https://img.shields.io/github/languages/count/vitorcarvalho67/Barium) ![GitHub stars](https://img.shields.io/github/languages/top/vitorcarvalho67/Barium) ![GitHub stars](https://img.shields.io/github/repo-size/vitorcarvalho67/Barium) ![GitHub stars](https://img.shields.io/github/languages/code-size/vitorcarvalho67/Barium)
# Barium (HMI)

[![GitHub license](https://img.shields.io/github/license/vitorcarvalho67/Barium)](vitorcarvalho67/Barium/blob/master/LICENSE)
![GitHub stars](https://img.shields.io/github/stars/vitorcarvalho67/Barium)
![GitHub language](https://img.shields.io/github/languages/top/vitorcarvalho67/Barium)
![GitHub last commit](https://img.shields.io/github/last-commit/vitorcarvalho67/Barium)
![GitHub repo size](https://img.shields.io/github/repo-size/vitorcarvalho67/Barium)
![GitHub contributors](https://img.shields.io/github/contributors/vitorcarvalho67/Barium)

Um software inovador que utiliza redes neurais, aprendizado de máquina e aprendizado profundo para rastrear movimentos corporais, como mãos, permitindo interações avançadas com o sistema operacional, incluindo ações predefinidas e um mouse virtual. Além disso, o projeto emprega técnicas de treinamento de redes neurais 4D, onde o tempo é uma das dimensões, abrindo possibilidades revolucionárias em diversos campos da tecnologia.

Expand Down
202 changes: 202 additions & 0 deletions src/collector/coletor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import csv
import cv2
import mediapipe as mp
import math
import numpy as np
from PIL import Image, ImageDraw
import time
import datetime
import pytz
import os

salvar_videos = True

fusoHorario = pytz.timezone('America/Sao_Paulo')
dia_atual = (datetime.datetime.now(fusoHorario)).strftime('%Y-%m-%d %H-%M-%S')

if salvar_videos:
diretorio = f"../video/video_{dia_atual}"
os.makedirs(diretorio)

intervalo = 100
quantidade_de_frames = 20

exibir_conexoes = True
mostrar_numeros = False
dataset = "../data/bariumData.csv"

def calcular_distancia(ponto1, ponto2):
return math.sqrt(((ponto2[0] - ponto1[0]) ** 2) + ((ponto2[1] - ponto1[1]) ** 2))

def aumentar_contraste(frane):


imagem = cv2.convertScaleAbs(frame)

return imagem

cap = cv2.VideoCapture(0)
mp_maos = mp.solutions.hands
maos = mp_maos.Hands(max_num_hands=1)

ponto_anterior = None
matriz = None

dados = []
numero = -1
iteracao = 0

matrizes = []

z = 0

while True:
coordenadas = []
for a in range(21):
coordenadas.append((0, 0))

sucesso, frame = cap.read()
if not sucesso:
continue

frame = cv2.flip(frame, 1)

resultados = maos.process(cv2.cvtColor(aumentar_contraste(frame), cv2.COLOR_BGR2RGB))

lista_pontos = []

if resultados.multi_hand_landmarks:
for pontos_mao in resultados.multi_hand_landmarks:
for idx, ponto in enumerate(pontos_mao.landmark):
altura, largura, _ = frame.shape
cx, cy = int(ponto.x * largura), int(ponto.y * altura)
if mostrar_numeros:
cv2.putText(frame, str(idx), (cx, cy), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1)
lista_pontos.append((cx, cy))

if lista_pontos:
x, y, w, h = cv2.boundingRect(np.array(lista_pontos))
tamanho_max = max(w, h)

centro_x = x + w // 2
centro_y = y + h // 2

x = centro_x - tamanho_max // 2
y = centro_y - tamanho_max // 2

x, y, w, h = x - 10, y - 10, tamanho_max + 20, tamanho_max + 20

cv2.rectangle(frame, (x, y), (x + w, y + h), 2)

if exibir_conexoes:
mp.solutions.drawing_utils.draw_landmarks(frame, pontos_mao, mp_maos.HAND_CONNECTIONS)

cv2.imshow("Câmera", aumentar_contraste(frame))

if not numero == -1 and iteracao < 20:
tempo_atual = time.time() * 1000

if tempo_atual - tempo_anterior >= intervalo or iteracao == 0:
tempo_anterior = tempo_atual

matriz = np.full((100, 100), -1, dtype=int)
if lista_pontos:
for idx, ponto in enumerate(lista_pontos):
x_rel = (ponto[0] - x) * 100 // w
y_rel = (ponto[1] - y) * 100 // h
valor = idx
matriz[y_rel][x_rel] = valor

iteracao += 1

else:
if iteracao == 20:
matrizes.append(numero)

dados.append(matrizes)
iteracao = 0
numero = -1
matrizes = []

valor_video = " "

if salvar_videos:
video.release()
valor_video += "e vídeo "

print(f"Dados{valor_video}registrados!")
iteracao = 0

key = cv2.waitKey(1) & 0xFF


if key in range(ord('0'), ord('9') + 1) and lista_pontos:
numero = chr(key)

tempo_anterior = time.time() * 1000

m_video = f'{diretorio}/video_{z}.mp4'
duracao_frame = 10

pre = cv2.VideoWriter_fourcc(*'mp4v')
video = cv2.VideoWriter(m_video, pre, duracao_frame, (100, 100))


z += 1
print(z)

if matriz is not None:
for linha in range(matriz.shape[0]):
for coluna in range(matriz.shape[1]):
elemento = matriz[coluna, linha]
if elemento != -1:
coordenadas[elemento] = ((linha, coluna))

foto = Image.new("RGB", (100, 100), "black")

draw = ImageDraw.Draw(foto)

for indice, (x,y) in enumerate(coordenadas):
# draw.text((x,y), str(indice), fill="white")
draw.text((x,y), str("."), fill="white")

foto = np.array(foto)
foto = cv2.resize(foto, (100, 100))

if salvar_videos:
video.write(foto)

matriz = None
diagonal = calcular_distancia((x, y), (x + w, y + h))
referencial = ((x + w, y + h))

linha = []

for (x, y) in coordenadas:
linha.append(str((x, y)))

linha.append(referencial)
linha.append(diagonal)

matrizes.append(linha)

if key == ord('e'):
break

cap.release()
cv2.destroyAllWindows()

file = dataset

dados_tratados = []

for linha in dados:
linha = [item for sublista in linha for item in sublista]

dados_tratados.append(linha)

with open(file, mode='a', newline='') as arquivo:
escrever = csv.writer(arquivo, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)

for linha in dados_tratados:
escrever.writerow(linha)

0 comments on commit 536b196

Please sign in to comment.