# Focus and FPS settings in opencv python

**URL:** https://forum.opencv.org/t/focus-and-fps-settings-in-opencv-python/3044
**Category:** Python
**Tags:** videoio
**Created:** [April 29, 2021, 10:27am UTC](https://forum.opencv.org/t/focus-and-fps-settings-in-opencv-python/3044 "2021-04-29T10:27:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Maheswari.R](https://avatars.discourse-cdn.com/v4/letter/m/839c29/32.png) [@Maheswari.R](https://forum.opencv.org/u/Maheswari.R)
#### Post date: [April 29, 2021, 10:27am UTC](https://forum.opencv.org/t/focus-and-fps-settings-in-opencv-python/3044/1 "2021-04-29T10:27:11Z")

</div>

Hi,

1. I am processing real time video from logitech c922 webcam in python. I can set width and hight using the below functions successfully:  
camera.set(cv2.CAP\_PROP\_FRAME\_HEIGHT, 720)  
camera.set(cv2.CAP\_PROP\_FRAME\_WIDTH, 1280)

However, I can’t able to set the focus type(manual) and FPS using below functions:  
camera.set(cv2.CAP\_PROP\_AUTOFOCUS, 0)  
camera.set(cv2.CAP\_PROP\_FOCUS, 30)  
camera.set(cv2.CAP\_PROP\_FPS, 50)

How to do it?

1. I have attached python code which displays realtime video with FPS.

```
import cv2
import time

font = cv2.FONT_HERSHEY_SIMPLEX

camera = cv2.VideoCapture(0)
camera.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080) #1080, 720, 360
camera.set(cv2.CAP_PROP_FRAME_WIDTH, 1920) #1920, 1280, 640

while True:
     start = time.time()
     ret, image = camera.read()
     [h, w, d] = image.shape
    
     if cv2.waitKey(1)& 0xFF == ord('q'):
         break;

     end = time.time()
     fps = "FPS: %.1f" % (1/(end - start))
     cv2.putText(image, fps, (0, 25), font, 1, (0, 0, 255), 2)
     cv2.imshow('Image', image)

 camera.release()
 cv2.destroyAllWindows()

```

Actual problem is for 1080p resolution FPS is 30. But i am getting 46 fps(oscillating values) sometimes as per the above calculation, while using logitech c922 webcam.

how to calculate FPS exactly? Is there any other formula to find it? or Is there any explanation behind it? Please help to let me know about it…

---

<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: [April 29, 2021, 4:22pm UTC](https://forum.opencv.org/t/focus-and-fps-settings-in-opencv-python/3044/2 "2021-04-29T16:22:36Z")

</div>

> [@Maheswari.R](#):
>
> ```auto
> end = time.time()
> 
> ```

that may have a resolution of ~16 milliseconds, or 10 ms, or anything really. do you see why that’d give you wildly varying FPS numbers?

let’s make it simple. count 100 frames, measure the time for those frames. that’s an average.

---

<div class="post-metadata">

### Author: ![Maheswari.R](https://avatars.discourse-cdn.com/v4/letter/m/839c29/32.png) [@Maheswari.R](https://forum.opencv.org/u/Maheswari.R)
#### Post date: [May 8, 2021, 7:07am UTC](https://forum.opencv.org/t/focus-and-fps-settings-in-opencv-python/3044/3 "2021-05-08T07:07:28Z")

</div>

Thanks for reply @crackwitz. I can get around 35 FPS by averaging FPS of 100 frames (That’s too greater than 30).

But why FPS is oscillating?
