2 pirongbing0020 pirongbing0020 于 2017.09.13 11:39 提问

C语言ioctl调曝光的问题

这是我调曝光的方法,试了v4l2_control的两种方式,这种可以调,但是保存图片发现不是每次曝光都正常。这是为什么,是这个V4L2_CID_EXPOSURE_ABSOLUTE参数不好还是摄像头问题。

 int set_exposure(int cam_fd, int exp_value) {
    struct v4l2_control ctrl;
    struct v4l2_queryctrl setting;
    int min, max, current, step, val_def;
    if (isv4l2Control(cam_fd, V4L2_CID_EXPOSURE_ABSOLUTE, &setting) < 0)
        return -1;
    min = setting.minimum;
    max = setting.maximum;
    step = setting.step;
    val_def = setting.default_value;
    current = v4l2GetControl(cam_fd, V4L2_CID_EXPOSURE_ABSOLUTE);
    printf("max %d, min %d, default %d, current %d \n", max, min, val_def,
            current);
    printf("start set exp\n");
    int ret;
    //设置曝光绝对值
    ctrl.id = V4L2_CID_EXPOSURE_ABSOLUTE;
    ctrl.value = exp_value;
    ret = ioctl(cam_fd, VIDIOC_S_CTRL, &ctrl);
    if (ret < 0) {
        printf("Set exposure failed (%d)\n", ret);
        return FALSE;
    } else
        printf("Control name:%s set to value:%d\n", setting.name, ctrl.value);
    return TRUE;
}

这是我尝试过不行的方式

 int ret; 
struct v4l2_controlctrl; 
ctrl.id = V4L2_CID_EXPOSURE; //得到曝光档次,A20接受从 -4到4 共9个档次
ret = ioctl(Handle, VIDIOC_G_CTRL,&ctrl); 
if (ret < 0) 
{ printf("Get exposure failed (%d)\n",ret); 
returnV4L2_UTILS_GET_EXPSURE_ERR; 
} 

printf("\nGet Exposure :[%d]\n",ctrl.value);

//设置曝光档次
ctrl.id = V4L2_CID_EXPOSURE; 
ctrl.value = -4; 
ret = ioctl(Handle, VIDIOC_S_CTRL,&ctrl); 
if (ret < 0) { printf("Set exposurefailed (%d)\n", ret); 
return V4L2_UTILS_SET_EXPSURE_ERR;} 

Csdn user default icon
上传中...
上传图片
插入图片