IntelRealSense / realsense-ros

ROS Wrapper for Intel(R) RealSense(TM) Cameras
http://wiki.ros.org/RealSense
Apache License 2.0
2.58k stars 1.76k forks source link

I open camera sucsess, but when I start streaming, error happened? Error message is "uvc_start_streaming error: Invalid parameter " #3238

Open justdomyself opened 6 days ago

justdomyself commented 6 days ago

Bellow is my source code,

static int lv_rgb_camare_uvc_init(LV_RGB_STREAM_T *lv_rgb_stream_p) {

uvc_error_t res;

// 初始化 libuvc
res = uvc_init(&ctx, NULL);
if (res < 0) {
    lv_error("uvc_init error, uvc_error_t res = %d!\r\n", res);
    return -1;
}

   //查找RGB摄像头
    res = uvc_find_device(ctx, &dev, 0x1bcf, 0x2cd1, NULL);
    if (res < 0) {
        lv_error("uvc_find_device error: %s\r\n", uvc_strerror(res));
        uvc_exit(ctx);
        return -1;
    }

    // 打开设备
    res = uvc_open(dev, &devRgb);
    if (res < 0) {
        lv_error("uvc_open error: : %s\r\n", uvc_strerror(res));
        uvc_unref_device(dev);
        uvc_exit(ctx);
        return -1;
    }

uvc_print_diag(devRgb, stderr);

const uvc_format_desc_t *format_desc = uvc_get_format_descs(devRgb);
const uvc_frame_desc_t *frame_desc = format_desc->frame_descs;

enum uvc_frame_format frame_format;
int width = 640;
int height = 480;
int fps = 10;

switch (format_desc->bDescriptorSubtype) {
case UVC_VS_FORMAT_MJPEG:
    frame_format = UVC_COLOR_FORMAT_MJPEG;
    break;
case UVC_VS_FORMAT_FRAME_BASED:
    frame_format = UVC_FRAME_FORMAT_H264;
    break;
default:
    frame_format = UVC_FRAME_FORMAT_YUYV;
    break;
}

if (frame_desc) {
    width = frame_desc->wWidth;
    height = frame_desc->wHeight;
    fps = 10000000 / frame_desc->dwDefaultFrameInterval;
}

printf("\nFirst format: (%4s) %dx%d %dfps\n", format_desc->fourccFormat, width, height, fps);

uint8_t mode = 1;// UVC_AUTO_EXPOSURE_MODE_AUTO;
uvc_error_t err = uvc_set_ae_mode(devRgb, mode);
lv_info("uvc_error_t err %d\r\n", (int)err);

int start_fps = g_rgb_frame_rate;

int start_width = 1600;
int start_height = 1200;

// 开启数据采集
res = uvc_get_stream_ctrl_format_size(devRgb, &ctrl, UVC_FRAME_FORMAT_MJPEG, start_width, start_height, start_fps);

lv_init_rgb_memory();

// 开始流
res = uvc_start_streaming(devRgb, &ctrl, lv_rgb_camera_callback, (void *)12345, 0);//(void *)12345
if (res < 0) {
    lv_error( "uvc_start_streaming error: %s\r\n", uvc_strerror(res) );
    uvc_close(devRgb);
    uvc_unref_device(dev);
    uvc_exit(ctx);
    return -1;
}

return 0;

}

MartyG-RealSense commented 6 days ago

Hi @justdomyself Does the error still occur if you use start_width = 1280, start_height = 720 and start_fps = 15