Jan-23-2020, 09:23 PM
(This post was last modified: Jan-23-2020, 09:23 PM by hernancrespo89.)
Hi, i know there are similar questions but they didn't solve my problem. I have been trying to read brightness of my webcam using OpenCV and QT. I have tried to implement my codes on 3 different files (main,view,model). I created get_brightness in models.py and i call it on views.py but i see statement has no effect warning, and print_brightness never works.
main.py
main.py
from PyQt5.QtWidgets import QApplication
from views import UI_Window
from models import Camera
if __name__ == '__main__': #hangi dosyaya sag tiklayip Run dersek o dosya main oluyor. eger dosya main ise kosul saglanmis oluyor.
camera = Camera(0) #0, webcam numarasi
app = QApplication([])
start_window = UI_Window(camera)
start_window.show()
app.exit(app.exec_())views.pyfrom 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):
super().__init__()
self.cam_num = cam_num
self.cam_num.open()
# Create a timer.
self.timer = QTimer()
self.timer.timeout.connect(self.nextFrameSlot)
self.timer.start(1000. / 24)
self.print_brightness
def nextFrameSlot(self):
frame = self.cam_num.read()
if frame is not None:
image = QImage(frame, frame.shape[1], frame.shape[0], QImage.Format_RGB888) # The image is stored using a 24-bit RGB format (8-8-8).
self.pixmap = QPixmap.fromImage(image)
def print_brightness(self):
print(Camera.get_brightness())models.pyimport 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):
# vc.set(5, fps) #set FPS
self.cap.set(3, width) # set width #propID =3 yani 3.property si width. 3.property i 480 yap
self.cap.set(4, height) # set height
return self.cap.isOpened()
def read(self):
rval, frame = self.cap.read()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
return frame
def get_brightness(self):
return self.cap.get(cv2.CAP_PROP_BRIGHTNESS)
