Files
HPE_mediapipe/hpe_ffmpeg.py
Arkadiy Strelnikov 5459e0f0ce First commit
2021-11-26 01:47:03 +07:00

67 lines
1.4 KiB
Python

import sys
import cv2
import time
from hpe_mp_class import hpe_mp_class
from pythonosc import udp_client
# Arguments
adress_input = "in.pipe1"
if len(sys.argv) > 1:
adress_input = sys.argv[1]
for i in range(0, 100):
if adress_input == str(i):
adress_input = i
osc_address = "10.199.0.14"
osc_port = 5005
client = udp_client.SimpleUDPClient(osc_address, osc_port)
showing = False
# Videocapture
cap = cv2.VideoCapture(adress_input)
# Preprocessing parameters
crop = 1.0
frame_width = int(crop*cap.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height = int(crop*cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
# FPS variables
pTime = 0
cTime = 0
# Mediapie class
mp_cl = hpe_mp_class()
while True:
# Reading frame
success, img = cap.read()
# Image preprocessing
img = cv2.resize(img, (frame_width, frame_height))
# Mediapipe
mp_cl.process(img)
mp_cl.show(img)
if showing:
# FPS
cTime = time.time()
fps = 1. / (cTime - pTime)
pTime = cTime
# Showing
img = cv2.flip(img, 1) # mirror
cv2.putText(img, str(int(fps)), (22, 32), cv2.FONT_HERSHEY_COMPLEX, 1, (0, 0, 0), 2)
cv2.putText(img, str(int(fps)), (20, 30), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
cv2.imshow("Main", img)
# get converted map
res = mp_cl.getJSON()
client.send_message("/pose/0", res)
# Interface
key = cv2.waitKey(1)
if key == 27:
break