@@ -1433,6 +1433,30 @@ static double icvGetPropertyCAM_V4L (CvCaptureCAM_V4L* capture,
1433
1433
sprintf (name, " Exposure" );
1434
1434
capture->control .id = V4L2_CID_EXPOSURE;
1435
1435
break ;
1436
+ case CV_CAP_PROP_FOCUS: {
1437
+ struct v4l2_control c;
1438
+ int v4l2_min;
1439
+ int v4l2_max;
1440
+ // we need to make sure that the autofocus is switch off, if available.
1441
+ capture->control .id = V4L2_CID_FOCUS_AUTO;
1442
+ v4l2_min = v4l2_get_ctrl_min (capture, capture->control .id );
1443
+ v4l2_max = v4l2_get_ctrl_max (capture, capture->control .id );
1444
+ if ( !((v4l2_min == -1 ) && (v4l2_max == -1 )) ) {
1445
+ // autofocus capability is supported, switch it off.
1446
+ c.id = capture->control .id ;
1447
+ c.value = 0 ;// off
1448
+ if ( v4l2_ioctl (capture->deviceHandle , VIDIOC_S_CTRL, &c) != 0 ){
1449
+ if (errno != ERANGE) {
1450
+ fprintf (stderr, " VIDEOIO ERROR: V4L2: Failed to set control \" %d\" (FOCUS_AUTO): %s (value %d)\n " , c.id , strerror (errno), c.value );
1451
+ return -1 ;
1452
+ }
1453
+ }
1454
+ }// lack of support should not be considerred an error.
1455
+
1456
+ sprintf (name, " Focus" );
1457
+ capture->control .id = V4L2_CID_FOCUS_ABSOLUTE;
1458
+ break ;
1459
+ }
1436
1460
default :
1437
1461
sprintf (name, " <unknown property string>" );
1438
1462
capture->control .id = property_id;
@@ -1650,6 +1674,27 @@ static int icvSetControl (CvCaptureCAM_V4L* capture, int property_id, double val
1650
1674
sprintf (name, " Exposure" );
1651
1675
capture->control .id = V4L2_CID_EXPOSURE;
1652
1676
break ;
1677
+ case CV_CAP_PROP_FOCUS:
1678
+ // we need to make sure that the autofocus is switch off, if available.
1679
+ capture->control .id = V4L2_CID_FOCUS_AUTO;
1680
+ v4l2_min = v4l2_get_ctrl_min (capture, capture->control .id );
1681
+ v4l2_max = v4l2_get_ctrl_max (capture, capture->control .id );
1682
+ if ( !((v4l2_min == -1 ) && (v4l2_max == -1 )) ) {
1683
+ // autofocus capability is supported, switch it off.
1684
+ c.id = capture->control .id ;
1685
+ c.value = 0 ;// off
1686
+ if ( v4l2_ioctl (capture->deviceHandle , VIDIOC_S_CTRL, &c) != 0 ){
1687
+ if (errno != ERANGE) {
1688
+ fprintf (stderr, " VIDEOIO ERROR: V4L2: Failed to set control \" %d\" (FOCUS_AUTO): %s (value %d)\n " , c.id , strerror (errno), c.value );
1689
+ return -1 ;
1690
+ }
1691
+ }
1692
+ }// lack of support should not be considerred an error.
1693
+
1694
+ // now set the manual focus
1695
+ sprintf (name, " Focus" );
1696
+ capture->control .id = V4L2_CID_FOCUS_ABSOLUTE;
1697
+ break ;
1653
1698
default :
1654
1699
sprintf (name, " <unknown property string>" );
1655
1700
capture->control .id = property_id;
0 commit comments