Skip to content

Commit e4b4735

Browse files
committed
add opencv
1 parent d733337 commit e4b4735

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

OpenCV/logo.png

350 KB
Loading

OpenCV/main.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import sys
2+
import cv2
3+
from PyQt5 import QtGui, QtWidgets
4+
5+
6+
class Ui_MainWindow(QtWidgets.QWidget):
7+
def __init__(self, parent=None):
8+
super(Ui_MainWindow, self).__init__(parent)
9+
10+
self.ui_init()
11+
12+
self.show_cv_image()
13+
14+
def ui_init(self):
15+
'''
16+
画界面,非常简单,就一个label,用来承载图片
17+
:return:
18+
'''
19+
20+
self.main_layout = QtWidgets.QHBoxLayout()
21+
self.label_image = QtWidgets.QLabel()
22+
self.main_layout.addWidget(self.label_image)
23+
self.setLayout(self.main_layout)
24+
25+
def show_cv_image(self):
26+
'''
27+
使用cv2读取图片并显示
28+
:return:
29+
'''
30+
31+
image = cv2.imread('logo.png')
32+
image = cv2.resize(image, (1200, 300))
33+
result = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
34+
# 构建QImage对象
35+
show_image = QtGui.QImage(result.data, result.shape[1], result.shape[0], QtGui.QImage.Format_RGB888)
36+
self.label_image.setPixmap(QtGui.QPixmap.fromImage(show_image))
37+
38+
39+
if __name__ == '__main__':
40+
app = QtWidgets.QApplication(sys.argv)
41+
ui = Ui_MainWindow()
42+
ui.show()
43+
sys.exit(app.exec_())

OpenCV/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
opencv-python
2+
pyqt5

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,6 @@
2424

2525
* 按钮框类控件 [源码下载](QAbstractButton) [博文地址](https://xugaoxiang.com/2020/04/19/pyqt5-11-button/)
2626

27-
* QThread使用 [源码下载](QThread) [博文地址](https://xugaoxiang.com/2020/04/19/pyqt5-12-qthread/)
27+
* QThread使用 [源码下载](QThread) [博文地址](https://xugaoxiang.com/2020/04/19/pyqt5-12-qthread/)
28+
29+
* 显示`opencv`图像格式 [源码下载](OpenCV) [博文地址](https://xugaoxiang.com/2021/04/14/pyqt5-16-opencv/)

0 commit comments

Comments
 (0)