pylibfreenect2 icon indicating copy to clipboard operation
pylibfreenect2 copied to clipboard

Timeout only in Python, not in C++

Open phistep opened this issue 3 years ago • 2 comments

Hi, I'm trying to simply access the different frame types, but using Python, I always get a timeout. I'm on Linux 5.4.101-1-MANJARO #1 SMP PREEMPT Fri Feb 26 11:18:55 UTC 2021 x86_64 GNU/Linux using Python 3.9.2, pylibfreenect 0.1.4 from pip and libfreenect2 0.2.0.p1-3 from AUR.

from pylibfreenect2.libfreenect2 import (Freenect2, SyncMultiFrameListener,
                                         FrameMap)

from pylibfreenect2.libfreenect2 import setGlobalLogger, createConsoleLogger
from pylibfreenect2 import LoggerLevel
setGlobalLogger(createConsoleLogger(LoggerLevel.Debug))

driver = Freenect2()
if driver.enumerateDevices() == 0:
    print("No device found")
    exit(-1)

kinect = driver.openDefaultDevice()
print("Serial:  ", kinect.getSerialNumber())
print("Firmware:", kinect.getFirmwareVersion())
print("Color Camera Params:", kinect.getColorCameraParams())
print("IR Camera Params:", kinect.getIrCameraParams())

listener = SyncMultiFrameListener()
frames = listener.waitForNewFrame(milliseconds=10e3)

if frames:
    for type_ in ['color', 'ir', 'depth']:
        frame = frames[type_]
        print(type_)
        print(frame.asarray())

    listener.release(frames)
else:
    print("Timed out!")

gives me

[Info] [Freenect2Impl] enumerating devices...
[Info] [Freenect2Impl] 19 usb devices connected
[Info] [Freenect2Impl] found valid Kinect v2 @3:2 with serial 002301142447
[Info] [Freenect2Impl] found 1 devices
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
[Error] [VaapiRgbPacketProcessorImpl] vaInitialize(display, &major_ver, &minor_ver): unknown libva error
[Info] [Freenect2DeviceImpl] opening...
[Info] [Freenect2DeviceImpl] transfer pool sizes rgb: 20*16384 ir: 60*8*33792
[Info] [Freenect2DeviceImpl] opened
Serial:   b'002301142447'
Firmware: b'<unknown>'
Color Camera Params: <pylibfreenect2.libfreenect2.ColorCameraParams object at 0x7fb1c75e1730>
IR Camera Params: <pylibfreenect2.libfreenect2.IrCameraParams object at 0x7fb1c74ce770>
Timed out!
[Info] [Freenect2DeviceImpl] closing...
[Info] [Freenect2DeviceImpl] releasing usb interfaces...
[Info] [Freenect2DeviceImpl] deallocating usb transfer pools...
[Info] [Freenect2DeviceImpl] closing usb device...
[Info] [Freenect2DeviceImpl] closed

If I run the following C++ code, everything works fine and I get the frames.

//...
#include <libfreenect2/libfreenect2.hpp>
#include <libfreenect2/frame_listener_impl.h>

bool mainloop = true;

int main(int argc, char* argv[]) {
	signal(SIGINT, signalHandler);

	std::cout << "libfreenect2 version: " << LIBFREENECT2_VERSION << std::endl;
	libfreenect2::Freenect2 freenect2;
	libfreenect2::Freenect2Device* device = 0;

	if (freenect2.enumerateDevices() == 0) {
		std::cout << "No device connected!" << std::endl;
		return -1;
	}

	std::string serial = freenect2.getDefaultDeviceSerialNumber();
	device = freenect2.openDevice(serial);
	if (device == 0) {
		std::cout << "Failed to open device!" << std::endl;
		return -2;
	}

	libfreenect2::SyncMultiFrameListener listener( libfreenect2::Frame::Color
										| libfreenect2::Frame::Ir
										| libfreenect2::Frame::Depth);
	libfreenect2::FrameMap frames;
	device->setColorFrameListener(&listener);
	device->setIrAndDepthFrameListener(&listener);

	if (!device->start()) {
		std::cout << "Could not start device" << std::endl;
	}
	while (mainloop) {
		if (!listener.waitForNewFrame(frames, 10e3)) {
			std::cout << "Timed out after 10s" << std::endl;
			mainloop = false;
			continue;
		}
		libfreenect2::Frame* rgb = frames[libfreenect2::Frame::Color];
		libfreenect2::Frame* ir = frames[libfreenect2::Frame::Ir];
		libfreenect2::Frame* depth = frames[libfreenect2::Frame::Depth];

		printFrameInfo(rgb);
		// ...

		listener.release(frames);
		usleep(1e6);
	}

	device->stop();
	device->close();
}

libfreenect2 version: 0.2.0
[Info] [Freenect2Impl] enumerating devices...
[Info] [Freenect2Impl] 19 usb devices connected
[Info] [Freenect2Impl] found valid Kinect v2 @3:3 with serial 002301142447
[Info] [Freenect2Impl] found 1 devices
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
[Error] [VaapiRgbPacketProcessorImpl] vaInitialize(display, &major_ver, &minor_ver): unknown libva error
[Info] [Freenect2DeviceImpl] opening...
[Info] [Freenect2DeviceImpl] transfer pool sizes rgb: 20*16384 ir: 60*8*33792
[Info] [Freenect2DeviceImpl] opened
[Info] [Freenect2DeviceImpl] starting...
[Info] [Freenect2DeviceImpl] submitting rgb transfers...
[Info] [Freenect2DeviceImpl] submitting depth transfers...
[Info] [Freenect2DeviceImpl] started
Frame [BGRx]
  1920x1080@4
  #10: 25554ms
  gamma [1.0--6.4]: 6.4
  gain [1.0--1.5]:  1.00024
  exp [0.5--60.0]:  59.9844
[Info] [DepthPacketStreamParser] 13 packets were lost
RGB Frame written to rgb.ppm
Frame [float]
  512x424@4
  #21: 24841ms
  gamma [1.0--6.4]: 0
  gain [1.0--1.5]:  0
  exp [0.5--60.0]:  0
max value: 65535
IR Frame written to ir.ppm
Frame [float]
  512x424@4
  #21: 24841ms
  gamma [1.0--6.4]: 0
  gain [1.0--1.5]:  0
  exp [0.5--60.0]:  0
max value: 4460.37
Depth Frame written to depth.ppm
[Info] [OpenGLDepthPacketProcessor] avg. time: 71.2081ms -> ~14.0434Hz
[Info] [Freenect2DeviceImpl] stopping...
[Info] [Freenect2DeviceImpl] canceling rgb transfers...
[Info] [Freenect2DeviceImpl] canceling depth transfers...
[Info] [Freenect2DeviceImpl] stopped
[Info] [Freenect2DeviceImpl] closing...
[Info] [Freenect2DeviceImpl] releasing usb interfaces...
[Info] [Freenect2DeviceImpl] deallocating usb transfer pools...
[Info] [Freenect2DeviceImpl] closing usb device...
[Info] [Freenect2DeviceImpl] closed
[Info] [Freenect2DeviceImpl] closing...
[Info] [Freenect2DeviceImpl] already closed, doing nothing

What am I doing wrong? I'd like to use Python, since there is a lot of moving parts included in the application I am trying to create. Current workaround is to write the data to FIFO sockets and read them from Python, but having it all in one application would be way easier to use (and maintain).

phistep avatar Mar 23 '21 23:03 phistep

Hi, I'm trying to simply access the different frame types, but using Python, I always get a timeout. I'm on Linux 5.4.101-1-MANJARO #1 SMP PREEMPT Fri Feb 26 11:18:55 UTC 2021 x86_64 GNU/Linux using Python 3.9.2, pylibfreenect 0.1.4 from pip and libfreenect2 0.2.0.p1-3 from AUR.

from pylibfreenect2.libfreenect2 import (Freenect2, SyncMultiFrameListener,
                                         FrameMap)

from pylibfreenect2.libfreenect2 import setGlobalLogger, createConsoleLogger
from pylibfreenect2 import LoggerLevel
setGlobalLogger(createConsoleLogger(LoggerLevel.Debug))

driver = Freenect2()
if driver.enumerateDevices() == 0:
    print("No device found")
    exit(-1)

kinect = driver.openDefaultDevice()
print("Serial:  ", kinect.getSerialNumber())
print("Firmware:", kinect.getFirmwareVersion())
print("Color Camera Params:", kinect.getColorCameraParams())
print("IR Camera Params:", kinect.getIrCameraParams())

listener = SyncMultiFrameListener()
frames = listener.waitForNewFrame(milliseconds=10e3)

if frames:
    for type_ in ['color', 'ir', 'depth']:
        frame = frames[type_]
        print(type_)
        print(frame.asarray())

    listener.release(frames)
else:
    print("Timed out!")

gives me

[Info] [Freenect2Impl] enumerating devices...
[Info] [Freenect2Impl] 19 usb devices connected
[Info] [Freenect2Impl] found valid Kinect v2 @3:2 with serial 002301142447
[Info] [Freenect2Impl] found 1 devices
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
[Error] [VaapiRgbPacketProcessorImpl] vaInitialize(display, &major_ver, &minor_ver): unknown libva error
[Info] [Freenect2DeviceImpl] opening...
[Info] [Freenect2DeviceImpl] transfer pool sizes rgb: 20*16384 ir: 60*8*33792
[Info] [Freenect2DeviceImpl] opened
Serial:   b'002301142447'
Firmware: b'<unknown>'
Color Camera Params: <pylibfreenect2.libfreenect2.ColorCameraParams object at 0x7fb1c75e1730>
IR Camera Params: <pylibfreenect2.libfreenect2.IrCameraParams object at 0x7fb1c74ce770>
Timed out!
[Info] [Freenect2DeviceImpl] closing...
[Info] [Freenect2DeviceImpl] releasing usb interfaces...
[Info] [Freenect2DeviceImpl] deallocating usb transfer pools...
[Info] [Freenect2DeviceImpl] closing usb device...
[Info] [Freenect2DeviceImpl] closed

If I run the following C++ code, everything works fine and I get the frames.

//...
#include <libfreenect2/libfreenect2.hpp>
#include <libfreenect2/frame_listener_impl.h>

bool mainloop = true;

int main(int argc, char* argv[]) {
	signal(SIGINT, signalHandler);

	std::cout << "libfreenect2 version: " << LIBFREENECT2_VERSION << std::endl;
	libfreenect2::Freenect2 freenect2;
	libfreenect2::Freenect2Device* device = 0;

	if (freenect2.enumerateDevices() == 0) {
		std::cout << "No device connected!" << std::endl;
		return -1;
	}

	std::string serial = freenect2.getDefaultDeviceSerialNumber();
	device = freenect2.openDevice(serial);
	if (device == 0) {
		std::cout << "Failed to open device!" << std::endl;
		return -2;
	}

	libfreenect2::SyncMultiFrameListener listener( libfreenect2::Frame::Color
										| libfreenect2::Frame::Ir
										| libfreenect2::Frame::Depth);
	libfreenect2::FrameMap frames;
	device->setColorFrameListener(&listener);
	device->setIrAndDepthFrameListener(&listener);

	if (!device->start()) {
		std::cout << "Could not start device" << std::endl;
	}
	while (mainloop) {
		if (!listener.waitForNewFrame(frames, 10e3)) {
			std::cout << "Timed out after 10s" << std::endl;
			mainloop = false;
			continue;
		}
		libfreenect2::Frame* rgb = frames[libfreenect2::Frame::Color];
		libfreenect2::Frame* ir = frames[libfreenect2::Frame::Ir];
		libfreenect2::Frame* depth = frames[libfreenect2::Frame::Depth];

		printFrameInfo(rgb);
		// ...

		listener.release(frames);
		usleep(1e6);
	}

	device->stop();
	device->close();
}
libfreenect2 version: 0.2.0
[Info] [Freenect2Impl] enumerating devices...
[Info] [Freenect2Impl] 19 usb devices connected
[Info] [Freenect2Impl] found valid Kinect v2 @3:3 with serial 002301142447
[Info] [Freenect2Impl] found 1 devices
libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)
[Error] [VaapiRgbPacketProcessorImpl] vaInitialize(display, &major_ver, &minor_ver): unknown libva error
[Info] [Freenect2DeviceImpl] opening...
[Info] [Freenect2DeviceImpl] transfer pool sizes rgb: 20*16384 ir: 60*8*33792
[Info] [Freenect2DeviceImpl] opened
[Info] [Freenect2DeviceImpl] starting...
[Info] [Freenect2DeviceImpl] submitting rgb transfers...
[Info] [Freenect2DeviceImpl] submitting depth transfers...
[Info] [Freenect2DeviceImpl] started
Frame [BGRx]
  1920x1080@4
  #10: 25554ms
  gamma [1.0--6.4]: 6.4
  gain [1.0--1.5]:  1.00024
  exp [0.5--60.0]:  59.9844
[Info] [DepthPacketStreamParser] 13 packets were lost
RGB Frame written to rgb.ppm
Frame [float]
  512x424@4
  #21: 24841ms
  gamma [1.0--6.4]: 0
  gain [1.0--1.5]:  0
  exp [0.5--60.0]:  0
max value: 65535
IR Frame written to ir.ppm
Frame [float]
  512x424@4
  #21: 24841ms
  gamma [1.0--6.4]: 0
  gain [1.0--1.5]:  0
  exp [0.5--60.0]:  0
max value: 4460.37
Depth Frame written to depth.ppm
[Info] [OpenGLDepthPacketProcessor] avg. time: 71.2081ms -> ~14.0434Hz
[Info] [Freenect2DeviceImpl] stopping...
[Info] [Freenect2DeviceImpl] canceling rgb transfers...
[Info] [Freenect2DeviceImpl] canceling depth transfers...
[Info] [Freenect2DeviceImpl] stopped
[Info] [Freenect2DeviceImpl] closing...
[Info] [Freenect2DeviceImpl] releasing usb interfaces...
[Info] [Freenect2DeviceImpl] deallocating usb transfer pools...
[Info] [Freenect2DeviceImpl] closing usb device...
[Info] [Freenect2DeviceImpl] closed
[Info] [Freenect2DeviceImpl] closing...
[Info] [Freenect2DeviceImpl] already closed, doing nothing

What am I doing wrong? I'd like to use Python, since there is a lot of moving parts included in the application I am trying to create. Current workaround is to write the data to FIFO sockets and read them from Python, but having it all in one application would be way easier to use (and maintain).

Did you get the solution ? i am getting the same error,thank you.

KP1-cmd avatar Mar 31 '21 09:03 KP1-cmd

Open the kinect v2 device such like this: demo.

MikoyChinese avatar Apr 12 '21 10:04 MikoyChinese