Segmentation fault (core dumped) with BODY_FORMAT::BODY_34

Hi, I wrote a pretty simple little program that takes the body masks from my ZED2, fuses them into one Mat and streams it via NDI. Everything is working fine, unless I change to BODY_FORMAT::BODY_34. In that case it immediately gives me a Segmentation fault (core dumped) error. Using the 18 or 38 point models causes no issue. What might be the reason for this particular problem with Body_34?

Hi,

Can you share a snippet of code that reproduces the issue please?

What ZED SDK version are you using?

Thanks.

Stereolabs Support

SDK 4.1.3 and CUDA V11.4.315 on a ZED Box

It’s basically the body detection sample code with activated segmentation, I grab the mask, convert it into a four channel cv::Mat and stream it via NDI. I figured out that the problem happens at

memcpy(p_frame_buffers1[frame_idx & 1], cv_image_4ch.data, resX * resY * 4);

where I buffer the converted 4 channel mask for the NDI part. So I’m not sure if it is even a StereoLabs SDK problem since conversion to CV Mat beore that step seems to work fine. But something must be different with the data since only Body_34 causes the issue?

Mat fused;
Bodies objects;
cv::Mat cv_image_4ch;

returned_state = zed.grab();

if (returned_state == ERROR_CODE::SUCCESS) {
returned_state = zed.retrieveBodies(objects, detection_parameters_rt);

sl::uchar1 pixel_value = 0;
fused.setTo(pixel_value);

if (!objects.body_list.empty()) {
for (const auto& obj : objects.body_list) {
Mat mask_data = obj.mask;
vectorsl::uint2 bbox_2d = obj.bounding_box_2d;
Vector2 origin = bbox_2d[0];
auto height = mask_data.getHeight();
auto width = mask_data.getWidth();

  	for (unsigned long y = 0; y < height; y++) {
  		for (unsigned long x = 0; x < width; x++) {
                returned_state = mask_data.getValue(x, y, &pixel_value, MEM::CPU); 
  			if (returned_state == ERROR_CODE::SUCCESS) {
  				if (pixel_value > 0) {
  					int fused_x = static_cast<int>(origin[0]) + x;
  					int fused_y = static_cast<int>(origin[1]) + y;
  					if (fused_x >= 0 && fused_x < fused.getWidth() &&
  						fused_y >= 0 && fused_y < fused.getHeight()) {
  						fused.setValue(fused_x, fused_y, pixel_value, MEM::CPU);
  					}
  				}
                }
            }
  	}
  	cv::Mat cv_image = slMat2cvMat(fused);
  	cv::cvtColor(cv_image, cv_image_4ch, cv::COLOR_GRAY2BGRA);
  }

}

 // <- CORE DUMPED AFTER THIS LINE ->

memcpy(p_frame_buffers1[frame_idx & 1], cv_image_4ch.data, resX * resY * 4);

NDI_video_frame1.p_data = (uint8_t*)p_frame_buffers1[frame_idx & 1];

NDIlib_send_send_video_v2(pNDI_send1, &NDI_video_frame1);
frame_idx++;
}

Hi,

There is nothing different between the body34 format and the other ones regarding the segmentation mask, that’s why I’m a bit confused with your issue.

I tried to reproduce your setup but I don’t have any crash on my side.

Does it happen all the time? At the first frame of detection?

Stereolabs Support

I’m just as confused. It reliably happens as soon as the first object is detected and I start processing its mask. I’ll compile it on my notebook later to check if I can reproduce the issue there.

For the project I’ll likely opt for the 38 model so it’s not a problem for now, just really weird.