473,386 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to print brightness using OpenCV and PyQt

I have been trying to click a button and print brightness. When i click button i see this error message
Expand|Select|Wrap|Line Numbers
  1. Process finished with exit code 1
Here is my try

main.py
Expand|Select|Wrap|Line Numbers
  1. from PyQt5.QtWidgets import QApplication
  2. from views import UI_Window
  3. from models import Camera
  4.  
  5. if __name__ == '__main__': 
  6.  
  7.     camera = Camera(0) #0, webcam numarasi
  8.  
  9.     app = QApplication([])
  10.     start_window = UI_Window(camera)
  11.     start_window.show()
  12.     app.exit(app.exec_())
  13.  
  14.  
views.py


Expand|Select|Wrap|Line Numbers
  1. from PyQt5.QtCore import QThread, QTimer
  2. from PyQt5.QtWidgets import QLabel, QWidget, QPushButton, QVBoxLayout, QApplication, QHBoxLayout, QMessageBox,  QMainWindow
  3. from PyQt5.QtGui import QPixmap, QImage
  4. from models import Camera
  5.  
  6.  
  7. class UI_Window(QWidget):
  8.  
  9.     def __init__(self, cam_num):
  10.         super().__init__()
  11.         self.cam_num = cam_num
  12.         self.cam_num.open()
  13.  
  14.         # Create a timer.
  15.         self.timer = QTimer()
  16.         self.timer.timeout.connect(self.nextFrameSlot)
  17.         self.timer.start(1000. / 24)
  18.  
  19.         layout = QVBoxLayout()
  20.         button_layout = QHBoxLayout()
  21.         btnCamera = QPushButton("Print Brightness")
  22.         btnCamera.clicked.connect(self.print_brightness)
  23.         button_layout.addWidget(btnCamera)
  24.         layout.addLayout(button_layout)
  25.  
  26.         # Add a label
  27.  
  28.         self.setLayout(layout)
  29.  
  30.     def nextFrameSlot(self):
  31.  
  32.         frame = self.cam_num.read()
  33.  
  34.         if frame is not None:
  35.             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).
  36.             self.pixmap = QPixmap.fromImage(image)
  37.  
  38.     def print_brightness(self):
  39.         print(Camera.get_brightness())
  40.  
  41.  
models.py
Expand|Select|Wrap|Line Numbers
  1. import cv2
  2.  
  3. class Camera:
  4.  
  5.     def __init__(self, cam_num):
  6.  
  7.         self.cap = cv2.VideoCapture(cam_num)
  8.         self.cam_num = cam_num
  9.  
  10.     def open(self, width=640, height=480, fps=30):
  11.         # vc.set(5, fps)  #set FPS
  12.         self.cap.set(3, width)  
  13.         self.cap.set(4, height)  # set height
  14.  
  15.         return self.cap.isOpened()
  16.  
  17.     def read(self):
  18.         rval, frame = self.cap.read()
  19.         frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
  20.         return frame
  21.  
  22.     def get_brightness(self):
  23.         return self.cap.get(cv2.CAP_PROP_BRIGHTNESS)
  24.  
Jan 23 '20 #1
0 1501

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Joshua Burvill | last post by:
Hello, I am trying to print something to a print server using the following function but I get errors, does anyone have any pointers? Rgds, Josh Traceback (most recent call last): File...
6
by: Kebmo | last post by:
The client insists on having a link or button that the user can click to view the printable version in the browser. I already have the css done for the print version, so thats not a problem. I...
16
by: John Baker | last post by:
HI; I feel like a fool..I put CUTE FTP in my last request for help --it should have been CUTE PDF! I have FTP on my mind because I have been working on a web based application, and somehow my...
1
by: milti | last post by:
Hi All!! Is there any way, I can avoid the Print Dialog from appearing multiple times? Let me be more clear. I've say three files. file1.html, file2.html and file3.html. there's a button...
3
by: brvan41 | last post by:
It's me again, you guys really helped a lot the last time I posted, and was needing a little more help. I've got 2 comboxes and a listbox. The user selects from the 2 and is being displayed in...
1
by: de4ever | last post by:
HI, i have created a windows service using wmi and c# for mantaining a log of all print jobs in the printing queue.It creates log of only those print jobs which are there when the service...
1
by: Mike | last post by:
Hi, I have a web application written in asp.net and C#. It generates a bunch of pdf file using crystal report. Now I need to batch print all those pdf files from a web page to user's local...
0
by: katiezhu | last post by:
I'm working a project. It's about screen control. I write the program using c/c++ in visual studio 2008. I just use my hand to replace mouse to control screen. The code is given below: //Must...
1
by: atakarim | last post by:
Actually I am developing an POS application for my own shop in web. Now for that in billing section have features like select the products and print bill. only two steps. but while click on...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.