# Focus can't be set on Logitech MX Brio

**URL:** https://forum.opencv.org/t/focus-cant-be-set-on-logitech-mx-brio/18093
**Category:** Python
**Tags:** videoio
**Created:** [June 27, 2024, 2:04am UTC](https://forum.opencv.org/t/focus-cant-be-set-on-logitech-mx-brio/18093 "2024-06-27T02:04:40Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![nyoung8](https://avatars.discourse-cdn.com/v4/letter/n/779978/32.png) [@nyoung8](https://forum.opencv.org/u/nyoung8)
#### Post date: [June 27, 2024, 2:04am UTC](https://forum.opencv.org/t/focus-cant-be-set-on-logitech-mx-brio/18093/1 "2024-06-27T02:04:41Z")

</div>

I am attempting to set focus on a webcam, and take a photo. However the focus is unwilling to change. I will be using this on a Raspberry Pi 5 as well. I’ll post my code snippet if anyone can take a look and help me work through it that would be very appreciated.

```auto
import cv2
import time

def camera_snapshot():
    cap = cv2.VideoCapture(0)

    cap.set(28, 0)
    # Set the resolution
    cap.set(cv2.CAP_PROP_FRAME_WIDTH, 3840) # Width
    cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 2160) # Height

    # Set focus
    cap.set(cv2.CAP_PROP_FOCUS, 20)

    # Additional delay to allow the camera to adjust to the new resolution
    time.sleep(.1)

    ret, frame = cap.read()

    if ret:
        cv2.imwrite('captured_image.jpg', frame)
        print("Image captured successfully")
    else:
        print("Failed to capture image")

    cap.release()

 amera_snapshot()

```

---

<div class="post-metadata">

### Author: ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)
#### Post date: [June 27, 2024, 3:11am UTC](https://forum.opencv.org/t/focus-cant-be-set-on-logitech-mx-brio/18093/2 "2024-06-27T03:11:21Z")

</div>

how do I put this…

it’s not gonna be as easy as you think.

servo focus takes a moment to settle. it takes a moment to even start moving.

there is no focus _in the world_ that you can just set and it instantly applies.

cameras make frames _at their own pace_. they don’t care when you’ll _ask_ for the frames. the frames get made regardless. there is buffering. “buffering” does _not_ mean a fixed lag. it means stuff will pile up, _unless_ you continually read it. first in, first out. that time.sleep() is pointless in that piece of code. it merely causes frames to pile up. the first read() is the very first frame, and it will be the same with or without any sleep(). with the sleep() it will merely be “older” because “now” is later.

if you just want to take a picture, there are a whole lot of programs for that. even command line programs. in the “raspberry pi” space, lots of people make lots of tools. most of them are junk. be aware of that when evaluating them. going by popularity is not necessarily going to help. even popular options may be junk. you should evaluate on technical merit.

OpenCV is not made to take snapshots. wrong library. OpenCV is for computer vision. you can use it for your snapshotting needs, but don’t expect things to be user-friendly. it’s a library, not a tool. you will have to know stuff at a depth that you weren’t aware of before.

you will need to read more than one frame. that’s for sure. if you read a few more, you _should_ see the focus setting taking effect.

---

<div class="post-metadata">

### Author: ![nyoung8](https://avatars.discourse-cdn.com/v4/letter/n/779978/32.png) [@nyoung8](https://forum.opencv.org/u/nyoung8)
#### Post date: [June 27, 2024, 3:29am UTC](https://forum.opencv.org/t/focus-cant-be-set-on-logitech-mx-brio/18093/3 "2024-06-27T03:29:19Z")

</div>

Thank you for your thorough response. I have no experience in computer vision, the plan is to collect lots of data via pictures using OpenCV then classify them. Not sure if it is the best option for what I want, just one of the first that I came across.

---

<div class="post-metadata">

### Author: ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)
#### Post date: [June 27, 2024, 4:14am UTC](https://forum.opencv.org/t/focus-cant-be-set-on-logitech-mx-brio/18093/4 "2024-06-27T04:14:07Z")

</div>

in that case, I’d recommend keeping the program running, showing live video continuously with `cv.imshow()` and companion functions

you can easily handle mouse clicks or any key presses while the image window is active.
