orbbec / OrbbecSDK-K4A-Wrapper

This repo is forked from Azure-kinect-Sensor-SDK,contain the K4A wrapper for OrbbecSDK.
https://www.orbbec.com/
MIT License
37 stars 7 forks source link

k4a::image destructor error when created by `create_from_buffer()` #92

Open AlexanderLeipnitz opened 3 days ago

AlexanderLeipnitz commented 3 days ago

I have a working workflow for converting the depth and IR image of a Femto Bolt to an OpenCV image and saving those images. When restoring the k4a::image of the depth and IR image from a cv::Mat in a loop for use with the body tracker, I have encountered an error when the destructor for each image is automatically called at the end of the loop. When I work with an Azure Kinect and the original Azure-Kinect-Sensor-SDK, the following code works great:

while (true) {
  cv::Mat depthMat;
  <code for reading the opencv matrix 'depthMat'>

  k4a::image depthImage = k4a::image::create_from_buffer(
              K4A_IMAGE_FORMAT_DEPTH16, depthMat.cols, depthMat.rows, depthMat.step,
              depthMat.data, depthMat.total() * 2, NULL, NULL);

  <further image processing>
}

When I use this wrapper and an Orbbec Femto Bolt, the create_from_buffer() method is successful and the depthImage is reconstructed correctly. However, if its destructor is called before the next depthImage is reconstructed in the next iteration, I get the following error:

terminate called after throwing an instance of 'std::bad_function_call'
  what():  bad_function_call
[ERROR   ] 2024-Oct-14 16:44:00.767482 Aborted!
[CALLSTACK]:
#0  0x7fb2d96d3e87 in gsignal from /lib/x86_64-linux-gnu/libc.so.6
    at /build/glibc-CVJwZb/glibc-2.27/signal/../sysdeps/unix/sysv/linux/nptl-signals.h:80
#1  0x7fb2d96d57f1 in abort from /lib/x86_64-linux-gnu/libc.so.6
    at /build/glibc-CVJwZb/glibc-2.27/stdlib/abort.c:79
#2  0x7fb2da0c8957 in  from libstdc++.so.6
#3  0x7fb2da0ceae6 in  from libstdc++.so.6
#4  0x7fb2da0cdb49 in  from libstdc++.so.6
#5  0x7fb2da0ce4b8 in __gxx_personality_v0 from libstdc++.so.6
#6  0x7fb2d9a96573 in  from libgcc_s.so.1
#7  0x7fb2d9a96ad1 in _Unwind_RaiseException from libgcc_s.so.1
#8  0x7fb2da0ced47 in __cxa_throw from libstdc++.so.6
#9  0x7fb2da0f7462 in  from libstdc++.so.6
#10  0x7fb2a087283a in std::function<void (void*, void*)>::operator()(void*, void*) const from libOrbbecSDK.so.1.10
#11  0x7fb2a0871153 in  from libOrbbecSDK.so.1.10
#12  0x7fb2a0872134 in  from libOrbbecSDK.so.1.10
#13  0x7fb2a08fd670 in std::function<void ()>::operator()() const from libOrbbecSDK.so.1.10
#14  0x7fb2a0e60642 in  from libOrbbecSDK.so.1.10
#15  0x7fb2a0e664be in  from libOrbbecSDK.so.1.10
zzuliys commented 3 days ago

I have a working workflow for converting the depth and IR image of a Femto Bolt to an OpenCV image and saving those images. When restoring the k4a::image of the depth and IR image from a cv::Mat in a loop for use with the body tracker, I have encountered an error when the destructor for each image is automatically called at the end of the loop. When I work with an Azure Kinect and the original Azure-Kinect-Sensor-SDK, the following code works great:

while (true) {
  cv::Mat depthMat;
  <code for reading the opencv matrix 'depthMat'>

  k4a::image depthImage = k4a::image::create_from_buffer(
            K4A_IMAGE_FORMAT_DEPTH16, depthMat.cols, depthMat.rows, depthMat.step,
            depthMat.data, depthMat.total() * 2, NULL, NULL);

  <further image processing>
}

When I use this wrapper and an Orbbec Femto Bolt, the create_from_buffer() method is successful and the depthImage is reconstructed correctly. However, if its destructor is called before the next depthImage is reconstructed in the next iteration, I get the following error:

terminate called after throwing an instance of 'std::bad_function_call'
  what():  bad_function_call
[ERROR   ] 2024-Oct-14 16:44:00.767482 Aborted!
[CALLSTACK]:
#0  0x7fb2d96d3e87 in gsignal from /lib/x86_64-linux-gnu/libc.so.6
    at /build/glibc-CVJwZb/glibc-2.27/signal/../sysdeps/unix/sysv/linux/nptl-signals.h:80
#1  0x7fb2d96d57f1 in abort from /lib/x86_64-linux-gnu/libc.so.6
    at /build/glibc-CVJwZb/glibc-2.27/stdlib/abort.c:79
#2  0x7fb2da0c8957 in  from libstdc++.so.6
#3  0x7fb2da0ceae6 in  from libstdc++.so.6
#4  0x7fb2da0cdb49 in  from libstdc++.so.6
#5  0x7fb2da0ce4b8 in __gxx_personality_v0 from libstdc++.so.6
#6  0x7fb2d9a96573 in  from libgcc_s.so.1
#7  0x7fb2d9a96ad1 in _Unwind_RaiseException from libgcc_s.so.1
#8  0x7fb2da0ced47 in __cxa_throw from libstdc++.so.6
#9  0x7fb2da0f7462 in  from libstdc++.so.6
#10  0x7fb2a087283a in std::function<void (void*, void*)>::operator()(void*, void*) const from libOrbbecSDK.so.1.10
#11  0x7fb2a0871153 in  from libOrbbecSDK.so.1.10
#12  0x7fb2a0872134 in  from libOrbbecSDK.so.1.10
#13  0x7fb2a08fd670 in std::function<void ()>::operator()() const from libOrbbecSDK.so.1.10
#14  0x7fb2a0e60642 in  from libOrbbecSDK.so.1.10
#15  0x7fb2a0e664be in  from libOrbbecSDK.so.1.10
  • OS with Version: Linux Mint 19.3 Cinnamon
  • SDK Version: 1.10.3
  • Firmware version: 1.0.9

I have a working workflow for converting the depth and IR image of a Femto Bolt to an OpenCV image and saving those images. When restoring the k4a::image of the depth and IR image from a cv::Mat in a loop for use with the body tracker, I have encountered an error when the destructor for each image is automatically called at the end of the loop. When I work with an Azure Kinect and the original Azure-Kinect-Sensor-SDK, the following code works great:

while (true) {
  cv::Mat depthMat;
  <code for reading the opencv matrix 'depthMat'>

  k4a::image depthImage = k4a::image::create_from_buffer(
            K4A_IMAGE_FORMAT_DEPTH16, depthMat.cols, depthMat.rows, depthMat.step,
            depthMat.data, depthMat.total() * 2, NULL, NULL);

  <further image processing>
}

When I use this wrapper and an Orbbec Femto Bolt, the create_from_buffer() method is successful and the depthImage is reconstructed correctly. However, if its destructor is called before the next depthImage is reconstructed in the next iteration, I get the following error:

terminate called after throwing an instance of 'std::bad_function_call'
  what():  bad_function_call
[ERROR   ] 2024-Oct-14 16:44:00.767482 Aborted!
[CALLSTACK]:
#0  0x7fb2d96d3e87 in gsignal from /lib/x86_64-linux-gnu/libc.so.6
    at /build/glibc-CVJwZb/glibc-2.27/signal/../sysdeps/unix/sysv/linux/nptl-signals.h:80
#1  0x7fb2d96d57f1 in abort from /lib/x86_64-linux-gnu/libc.so.6
    at /build/glibc-CVJwZb/glibc-2.27/stdlib/abort.c:79
#2  0x7fb2da0c8957 in  from libstdc++.so.6
#3  0x7fb2da0ceae6 in  from libstdc++.so.6
#4  0x7fb2da0cdb49 in  from libstdc++.so.6
#5  0x7fb2da0ce4b8 in __gxx_personality_v0 from libstdc++.so.6
#6  0x7fb2d9a96573 in  from libgcc_s.so.1
#7  0x7fb2d9a96ad1 in _Unwind_RaiseException from libgcc_s.so.1
#8  0x7fb2da0ced47 in __cxa_throw from libstdc++.so.6
#9  0x7fb2da0f7462 in  from libstdc++.so.6
#10  0x7fb2a087283a in std::function<void (void*, void*)>::operator()(void*, void*) const from libOrbbecSDK.so.1.10
#11  0x7fb2a0871153 in  from libOrbbecSDK.so.1.10
#12  0x7fb2a0872134 in  from libOrbbecSDK.so.1.10
#13  0x7fb2a08fd670 in std::function<void ()>::operator()() const from libOrbbecSDK.so.1.10
#14  0x7fb2a0e60642 in  from libOrbbecSDK.so.1.10
#15  0x7fb2a0e664be in  from libOrbbecSDK.so.1.10
  • OS with Version: Linux Mint 19.3 Cinnamon
  • SDK Version: 1.10.3
  • Firmware version: 1.0.9

Now you must pass in the relevant parameters, otherwise an error will be reported. We will consider compatibility in future versions. image

AlexanderLeipnitz commented 1 day ago

Thank you. I fixed the issue by defining the callback (k4a_memory_destroy_cb_t *buffer_release_cb) as [](void* _buffer, void* ctx) instead of NULL. It seems to be a bug in this Wrapper indeed.