Ask Your Question

How to set and get brightness of camera using PyQt

asked 2020-01-24 06:11:08 -0500

hernancrespo gravatar image

Hi, I have been trying to set and get brightness value of webcam when i press button. I want to set brightness then read it. When i read brightness it prints 0.0 which is not the actual value. And set_brightness has no effect

Here is my full code

from PyQt5.QtWidgets import QApplication
from views import UI_Window
from models import Camera

if __name__ == '__main__':

    camera = Camera(0)
    app = QApplication([])
    start_window = UI_Window(camera)

import cv2

class Camera:

    def __init__(self, cam_num):

        self.cap = cv2.VideoCapture(cam_num)
        self.cam_num = cam_num

    def open(self, width=640, height=480, fps=30):
        self.cap.set(5, fps)  #set FPS
        self.cap.set(3, width)  
        self.cap.set(4, height)
        return self.cap.isOpened()

    def read(self):
        rval, frame =
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        return frame

    def get_brightness(self):
        return self.cap.get(cv2.CAP_PROP_BRIGHTNESS)

    def set_brightness(self, value):
        self.cap.set(cv2.CAP_PROP_BRIGHTNESS, value)

from PyQt5.QtCore import QThread, QTimer
from PyQt5.QtWidgets import QLabel, QWidget, QPushButton, QVBoxLayout, QApplication, QHBoxLayout, QMessageBox,  QMainWindow
from PyQt5.QtGui import QPixmap, QImage
from models import Camera

class UI_Window(QWidget):

    def __init__(self, cam_num):
        self.cam_num = cam_num
        # Create a timer.
        self.timer = QTimer()
        self.timer.start(1000. / 24)
        layout = QVBoxLayout()
        button_layout = QHBoxLayout()
        btnCamera = QPushButton("Print Brightness")
        # Add a label

    def nextFrameSlot(self):
        frame =
        if frame is not None:
            image = QImage(frame, frame.shape[1], frame.shape[0], QImage.Format_RGB888)
            self.pixmap = QPixmap.fromImage(image)

    def print_brightness(self):
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2020-01-24 08:26:32 -0500

berak gravatar image

updated 2020-01-24 08:28:07 -0500

When i read brightness it prints 0.0 which is not the actual value. And set_brightness has no effect

not all webcam / driver / os combinations support this, also likely it will ignore your attempt at setting fps.

(a case of "bad luck", and for sure unrelated to your gui efforts)

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2020-01-24 06:11:08 -0500

Seen: 27 times

Last updated: Jan 24