• 大小: 4KB
    文件类型: .py
    金币: 2
    下载: 1 次
    发布日期: 2021-06-08
  • 语言: Python
  • 标签: python  cv2  qt5  

资源简介

本代码小巧玲珑,实现一个界面,且在界面上有打开相机按钮和关闭相机按钮。可打开电脑相机或usb相机。

资源截图

代码片段和文件信息

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys
import cv2

from PyQt5 import QtCore QtGuiQtWidgets
import os
# reload(sys)
# sys.setdefaultencoding(‘utf-8‘)

class Ui_MainWindow(QtWidgets.QWidget):
    def __init__(self parent=None):
        super(Ui_MainWindow self).__init__(parent)

        # self.face_recong = face.Recognition()
        self.timer_camera = QtCore.QTimer()
        self.cap = cv2.VideoCapture()
        self.CAM_NUM = 0
        self.set_ui()
        self.slot_init()
        self.__flag_work = 0
        self.x =0

    def set_ui(self):

        self.__layout_main = QtWidgets.QHBoxLayout()
        self.__layout_fun_button = QtWidgets.QVBoxLayout()
        self.__layout_data_show = QtWidgets.QVBoxLayout()



        self.button_open_camera = QtWidgets.QPushButton(u‘打开相机‘)

        self.button_close = QtWidgets.QPushButton(u‘退出‘)
        self.button_open_camera.setMinimumHeight(50)
        self.button_close.setMinimumHeight(50)

        self.button_close.move(10100)

        # 信息显示
        self.label_show_camera = QtWidgets.QLabel()
        self.label_move = QtWidgets.QLabel()
        self.label_move.setFixedSize(200 200)

        self.label_show_camera.setFixedSize(641 481)
        self.label_show_camera.setAutoFillBackground(False)

        self.__layout_fun_button.addWidget(self.button_open_camera)
        self.__layout_fun_button.addWidget(self.button_close)
        self.__layout_fun_button.addWidget(self.label_move)

        self.__layout_main.addLayout(self.__layout_fun_button)
        self.__layout_main.addWidget(self.label_show_camera)

        self.setLayout(self.__layout_main)
        self.label_move.raise_()
        self.setWindowtitle(u‘这是软件的名称‘)

    # def mousePressEvent(self QMouseEvent):
    #     x = QMouseEvent.x()
    #     y = QMouseEvent.y()
    #     self.label_move.move(00)
    #     print(xy)
    #     print(self.label_move.pos())

    def slot_init(self):
        self.button_open_camera.clicked.connect(self.button_open_camera_click)
        self.timer_camera.timeout.connect(self.show_camera)
        self.button_close.clicked.connect(self.close)


    def button_open_camera_click(self):
        if self.timer_camera.isAc

评论

共有 条评论