728x90
반응형
설치
pip install mss
import sys
import cv2 as cv
from PyQt5.QtCore import QThread
from PyQt5.QtWidgets import QWidget, QApplication, QPushButton, QBoxLayout, QLabel
from PyQt5 import QtGui
import numpy as np
import mss
class Image_View(QThread):
def __init__(self):
super().__init__()
def __del__(self):
self.wait()
def run(self):
image_pos = {'left': 0, 'top': 0, 'width': 80, 'height': 80}
width = image_pos['width']
height = image_pos['height']
label.resize(width, height)
while True:
with mss.mss() as sct:
image_pos1 = np.array(sct.grab(image_pos))[:, :, :3]
img = cv.cvtColor(image_pos1, cv.COLOR_BGR2RGB)
h,w,c = img.shape
qImg = QtGui.QImage(img.data, w, h, w*c, QtGui.QImage.Format_RGB888)
pixmap = QtGui.QPixmap.fromImage(qImg)
label.setPixmap(pixmap)
class MainWindow(QWidget):
def __init__(self):
super().__init__()
form_lbx = QBoxLayout(QBoxLayout.TopToBottom, self)
self.pb1 = QPushButton('Screen On')
self.pb2 = QPushButton('test2')
# self.label = QLabel()
self.th = Image_View()
form_lbx.addWidget(label)
form_lbx.addWidget(self.pb1)
form_lbx.addWidget(self.pb2)
self.setLayout(form_lbx)
self.pb1.clicked.connect(self.slot_clicked_pb1)
def slot_clicked_pb1(self):
self.th.start()
print('pb1 clicked')
if __name__ == "__main__":
app = QApplication(sys.argv)
label = QLabel()
form = MainWindow()
form.show()
app.exec_()
mss 를 사용하여 실시간 스크린샷을 읽어서
QImage 로 화면을 표시했습니다.
728x90
반응형
'공부 > Open cv' 카테고리의 다른 글
오류 해결 (0) | 2022.01.05 |
---|---|
명령어 목록 (0) | 2021.12.09 |
2. [python_Open cv] cv2.threshold (0) | 2019.12.26 |
1. [python_Open cv] cvtColor (0) | 2019.12.26 |