Callback function does not provide color frames with depth frames
Hi,
i am trying to get color and depth frames using a callback function.
While using rs2_pipeline_start_with_config_and_callback i am getting only the depth frames. While using pooling via rs2_pipeline_start_with_config i am getting right the color and depth frames.
Configuration with only color stream works fine.
Is threre any further configuration to enable color frames? Thank you.
RS2_API_MAJOR_VERSION 2
RS2_API_MINOR_VERSION 47
Code for testing:
#include <librealsense2/rs.h>
#include <librealsense2/h/rs_pipeline.h>
#include <librealsense2/h/rs_option.h>
#include <librealsense2/h/rs_frame.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
int check_rs_error(
rs2_error* e
) {
if (e != NULL) {
printf(
"%s(%s) -> %s\n",
rs2_get_failed_function(e),
rs2_get_failed_args(e),
rs2_get_error_message(e));
return(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}
void frame_callback(
rs2_frame *frame,
void *args
) {
rs2_stream type;
rs2_format format;
int index, uid, fps;
rs2_error* e = NULL;
const rs2_stream_profile *stream_profile =
rs2_get_frame_stream_profile(frame, &e);
check_rs_error(e);
rs2_get_stream_profile_data(
stream_profile, &type, &format, &index, &uid, &fps, &e);
check_rs_error(e);
printf("%s\n", rs2_stream_to_string(type));
rs2_release_frame(frame);
}
int main(int argc, char *argv[]) {
rs2_device* dev;
rs2_pipeline* pipeline;
rs2_pipeline_profile* pipeline_profile;
rs2_config* config;
rs2_error* e = NULL;
int dev_count;
rs2_context* ctx;
rs2_device_list* device_list;
ctx = rs2_create_context(RS2_API_VERSION, &e);
check_rs_error(e);
device_list = rs2_query_devices(ctx, &e);
check_rs_error(e);
dev_count = rs2_get_device_count(device_list, &e);
check_rs_error(e);
if (dev_count == 0) {
printf("dev_count == 0\n");
return EXIT_FAILURE;
}
dev = rs2_create_device(device_list, 0, &e);
if (dev == NULL) {
printf("dev == NULL\n");
return EXIT_FAILURE;
}
pipeline = rs2_create_pipeline(ctx, &e);
check_rs_error(e);
config = rs2_create_config(&e);
check_rs_error(e);
rs2_config_enable_stream(
config, RS2_STREAM_COLOR, 0, 960, 540, RS2_FORMAT_RGB8, 6, &e);
check_rs_error(e);
rs2_config_enable_stream(
config, RS2_STREAM_DEPTH, 0, 320, 240, RS2_FORMAT_Z16, 30, &e);
check_rs_error(e);
if (argc >= 2) {
pipeline_profile = rs2_pipeline_start_with_config_and_callback(
pipeline, config, frame_callback, NULL, &e);
check_rs_error(e);
sleep(10);
} else {
pipeline_profile = rs2_pipeline_start_with_config(pipeline, config, &e);
check_rs_error(e);
rs2_stream type;
rs2_format format;
int index, uid, fps;
for (size_t i = 0; i < 100; ++i) {
rs2_frame* frames =
rs2_pipeline_wait_for_frames(pipeline, RS2_DEFAULT_TIMEOUT, &e);
check_rs_error(e);
int num_of_frames = rs2_embedded_frames_count(frames, &e);
check_rs_error(e);
for (int i = 0; i < num_of_frames; ++i) {
rs2_frame* frame = rs2_extract_frame(frames, i, &e);
check_rs_error(e);
const rs2_stream_profile *stream_profile =
rs2_get_frame_stream_profile(frame, &e);
check_rs_error(e);
rs2_get_stream_profile_data(
stream_profile, &type, &format, &index, &uid, &fps, &e);
check_rs_error(e);
printf("%s\n", rs2_stream_to_string(type));
rs2_release_frame(frame);
}
rs2_release_frame(frames);
}
}
return EXIT_SUCCESS;
}
-
rs2_config_enable_stream(
config, RS2_STREAM_COLOR, 0, 960, 540, RS2_FORMAT_RGB8, 6, &e);
check_rs_error(e);
rs2_config_enable_stream(
config, RS2_STREAM_DEPTH, 0, 320, 240, RS2_FORMAT_Z16, 30, &e);
check_rs_error(e);Looks like you're running your colour stream at 6fps while your depth stream runs at 30fps. Does the problem remain if you run them both at 30fps?
Please sign in to leave a comment.
Comments
4 comments