Usando o Pylibfreenect2 no Ubuntu 19.04

1. Usando o Pylibfreenect2 no Ubuntu 19.04

Thales Ryu Ito
Odacchi

(usa Ubuntu)

Enviado em 16/12/2019 - 09:46h

Bom dia,

estou tentando usar o Pylibfreenect2 para a captura de imagens de dois kinects simultaneamente. Consigo com um kinect, porém, quando rodo um código para capturar os dois, não consigo.
Abaixo está o código que estou tentando usar.

# coding: utf-8

import numpy as np
import cv2
import sys
from pylibfreenect2 import Freenect2, SyncMultiFrameListener
from pylibfreenect2 import FrameType, Registration, Frame
from pylibfreenect2 import createConsoleLogger, setGlobalLogger
from pylibfreenect2 import LoggerLevel
import time

try:
from pylibfreenect2 import OpenGLPacketPipeline
pipeline = OpenGLPacketPipeline()
except:
try:
from pylibfreenect2 import OpenCLPacketPipeline
pipeline = OpenCLPacketPipeline()
except:
from pylibfreenect2 import CpuPacketPipeline
pipeline = CpuPacketPipeline()
print("Packet pipeline:", type(pipeline).__name__)


inicio = time.time()
# Create and set logger
logger = createConsoleLogger(LoggerLevel.Debug)
setGlobalLogger(logger)

fn = Freenect2()
num_devices = fn.enumerateDevices()
if num_devices == 0:
print("No device connected!")
sys.exit(1)

serial = fn.getDeviceSerialNumber(1)
device = fn.openDevice(serial, pipeline=pipeline)
serial2 = fn.getDeviceSerialNumber(0)
device2 = fn.openDevice(serial2, pipeline=pipeline)

listener = SyncMultiFrameListener(
FrameType.Color | FrameType.Ir | FrameType.Depth)
listener2 = SyncMultiFrameListener(
FrameType.Color | FrameType.Ir | FrameType.Depth)

# Register listeners
device.setColorFrameListener(listener)
device.setIrAndDepthFrameListener(listener)
device2.setColorFrameListener(listener2)
device2.setIrAndDepthFrameListener(listener2)

device.start()
device2.start()

# NOTE: must be called after device.start()
registration = Registration(device.getIrCameraParams(),
device.getColorCameraParams())
registration2 = Registration(device2.getIrCameraParams(),
device2.getColorCameraParams())

undistorted = Frame(512, 424, 4)
registered = Frame(512, 424, 4)

# Optinal parameters for registration
# set True if you need
need_bigdepth = False
need_color_depth_map = False

bigdepth = Frame(1920, 1082, 4) if need_bigdepth else None
color_depth_map = np.zeros((424, 512), np.int32).ravel() \
if need_color_depth_map else None

aux = 0

while True:
frames = listener.waitForNewFrame()
color = frames["color"]
ir = frames["ir"]
depth = frames["depth"]
frames2 = listener2.waitForNewFrame()
color2 = frames2["color"]
ir2 = frames2["ir"]
depth2 = frames2["depth"]

registration.apply(color, depth, undistorted, registered,
bigdepth=bigdepth,
color_depth_map=color_depth_map)
registration2.apply(color2, depth2, undistorted, registered,
bigdepth=bigdepth,
color_depth_map=color_depth_map)

# NOTE for visualization:
# cv2.imshow without OpenGL backend seems to be quite slow to draw all
# things below. Try commenting out some imshow if you don't have a fast
# visualization backend.
#cv2.imshow("ir", ir.asarray() / 65535.)
#cv2.imwrite("/home/thales/testes/teste" + str(aux) + ".jpg", ir.asarray() / 65535.)
#cv2.imshow("depth", depth.asarray() / 4500.)
#cv2.imwrite("/home/thales/testes/teste" + str(aux) + ".jpg", depth.asarray() / 2000.)
#cv2.imshow("color1", cv2.resize(color.asarray(), (int(1920 / 3), int(1080 / 3))))
#cv2.imshow("color2", cv2.resize(color2.asarray(), (int(1920 / 3), int(1080 / 3))))
cv2.imwrite("/home/thales/testes/teste" + str(aux) + ".jpg", color.asarray())
cv2.imwrite("/home/thales/testes2/teste" + str(aux) + ".jpg", color2.asarray())
#cv2.imshow("registered", registered.asarray(np.uint8))

#if need_bigdepth:
# cv2.imshow("bigdepth", cv2.resize(bigdepth.asarray(np.float32),
# (int(1920 / 3), int(1082 / 3))))
#if need_color_depth_map:
# cv2.imshow("color_depth_map", color_depth_map.reshape(424, 512))
aux += 1
listener.release(frames)
listener2.release(frames2)
key = cv2.waitKey(delay=1)
if key == ord('q'):
fim = time.time()
print(fim - inicio)
break

device.stop()
device.close()

sys.exit(0)


E o erro que ocorre é o seguinte: [Debug] [DepthPacketStreamParser] subpacket too large
Fiz umas pesquisas e vi que não consideram isso como um erro, já que é normal a perda de alguns pacotes, o problema é que no meu caso, ocorre a perda de todos os pacotes e nenhum arquivo é salvo.
Agradeço antecipadamente qualquer ajuda.


  






Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts