程序示例精选
Python+Qt图像处理长宽面积检测识别
如需安装运行环境或远程调试,见文章底部个人QQ名片,由专业技术人员远程协助!
前言
这篇博客针对《Python+Qt图像处理长宽面积检测识别》编写代码,代码整洁,规则,易读。 学习与应用推荐首选。
运行结果
文章目录
一、所需工具软件
二、使用步骤
1. 主要代码
2. 运行结果
三、在线协助
一、所需工具软件
1. Python
2. Pycharm
二、使用步骤
代码如下(示例):
# coding:utf-8
import sys
import cv2
from PyQt5 import QtWidgets
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import numpy as np
global imgName
global imgT
imgT=[]
global enhanced_image
enhanced_image=[]
global binary_image
binary_image=[]
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(579, 554)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(Dialog.sizePolicy().hasHeightForWidth())
Dialog.setSizePolicy(sizePolicy)
self.gridLayout_2 = QtWidgets.QGridLayout(Dialog)
self.gridLayout_2.setObjectName("gridLayout_2")
self.frame = QtWidgets.QFrame(Dialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(5)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.frame.sizePolicy().hasHeightForWidth())
self.frame.setSizePolicy(sizePolicy)
self.frame.setFrameShape(QtWidgets.QFrame.Box)
self.frame.setFrameShadow(QtWidgets.QFrame.Sunken)
self.frame.setObjectName("frame")
self.gridLayout = QtWidgets.QGridLayout(self.frame)
self.gridLayout.setObjectName("gridLayout")
self.label = QtWidgets.QLabel(self.frame)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(1)
sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
self.label.setSizePolicy(sizePolicy)
self.label.setStyleSheet("background-color: rgb(255, 255, 255);")
self.label.setText("")
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.label.setObjectName("label")
self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
self.label_2 = QtWidgets.QLabel(self.frame)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(1)
sizePolicy.setHeightForWidth(self.label_2.sizePolicy().hasHeightForWidth())
self.label_2.setSizePolicy(sizePolicy)
self.label_2.setStyleSheet("background-color: rgb(255, 255, 255);")
self.label_2.setText("")
self.label_2.setAlignment(QtCore.Qt.AlignCenter)
self.label_2.setObjectName("label_2")
self.gridLayout.addWidget(self.label_2, 1, 0, 1, 1)
self.label_4 = QtWidgets.QLabel(self.frame)
self.label_4.setStyleSheet("background-color: rgb(255, 255, 255);")
self.label_4.setText("")
self.label_4.setObjectName("label_4")
self.gridLayout.addWidget(self.label_4, 0, 1, 1, 1)
self.label_5 = QtWidgets.QLabel(self.frame)
self.label_5.setStyleSheet("background-color: rgb(255, 255, 255);")
self.label_5.setText("")
self.label_5.setObjectName("label_5")
self.gridLayout.addWidget(self.label_5, 1, 1, 1, 1)
self.gridLayout_2.addWidget(self.frame, 1, 1, 5, 1)
self.frame_2 = QtWidgets.QFrame(Dialog)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(1)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.frame_2.sizePolicy().hasHeightForWidth())
self.frame_2.setSizePolicy(sizePolicy)
self.frame_2.setFrameShape(QtWidgets.QFrame.Box)
self.frame_2.setFrameShadow(QtWidgets.QFrame.Sunken)
self.frame_2.setObjectName("frame_2")
self.gridLayout_3 = QtWidgets.QGridLayout(self.frame_2)
self.gridLayout_3.setObjectName("gridLayout_3")
self.pushButton_10 = QtWidgets.QPushButton(self.frame_2)
font = QtGui.QFont()
font.setFamily("微软雅黑")
font.setPointSize(12)
self.pushButton_10.setFont(font)
self.pushButton_10.setObjectName("pushButton_10")
self.gridLayout_3.addWidget(self.pushButton_10, 2, 0, 1, 1)
self.pushButton_2 = QtWidgets.QPushButton(self.frame_2)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
class myWin(QtWidgets.QWidget, Ui_Dialog):
def __init__(self):
super(myWin, self).__init__()
self.setupUi(self)
# 按钮信号槽代码
self.pushButton.clicked.connect(self.openFileButton)
self.pushButton_10.clicked.connect(self.contrastEnhancement)
self.pushButton_4.clicked.connect(self.grayscaleRun)
def openFileButton(self):
global imgName
global imgT
imgName, imgType = QFileDialog.getOpenFileName(self,"打开文件","./waitRecognPhoto","files(*.*)")
imgT = cv2.imread(imgName)
# height, width, pixels = img.shape
# print("width,height",width,height)
# print("self.label.width()",self.label.width())
# print("self.label.height()",self.label.height())
# rheight = height
# rwidth = width
# frame = cv2.resize(img, (int(rwidth), int(rwidth)))
# print("rwidth-elif,rheight-elfi", rwidth, rheight)
# img2 = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # opencv读取的bgr格式图片转换成rgb格式
# _image = QtGui.QImage(img2[:], img2.shape[1], img2.shape[0], img2.shape[1] * 3, QtGui.QImage.Format_RGB888)
# jpg_out = QtGui.QPixmap(_image).scaled(rwidth, rheight) # 设置图片大小
# self.label.setPixmap(jpg_out) # 设置图片显示
frame = cv2.cvtColor(imgT, cv2.COLOR_BGR2RGB)
height, width, bytesPerComponent = frame.shape
bytesPerLine = bytesPerComponent * width
# q_image = QtGui.QImage(frame.data, width, height, bytesPerLine, QtGui.QImage.Format_RGB888) \
# .scaled(label.height() * 0.8, label.height() * 0.6)
# label.setPixmap(QPixmap.fromImage(q_image))
# label.repaint() # Force the label to update its display
q_image = QtGui.QImage(frame.data, width, height, bytesPerLine, QtGui.QImage.Format_RGB888)
q_image = q_image.scaledToWidth(self.label.width()).scaledToHeight(self.label.height())
self.label.setPixmap(QPixmap.fromImage(q_image))
self.label.setScaledContents(True)
self.label.repaint()
if __name__=="__main__":
import sys
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
app=QtWidgets.QApplication(sys.argv)
Widget=myWin()
Widget.showMaximized();
Widget.show()
sys.exit(app.exec_())
运行结果
三、在线协助:
如需安装运行环境或远程调试,见文章底部个人 QQ 名片,由专业技术人员远程协助!
1)远程安装运行环境,代码调试
2)Visual Studio, Qt, C++, Python编程语言入门指导
3)界面美化
4)软件制作
5)云服务器申请
6)网站制作
当前文章连接:https://blog.csdn.net/alicema1111/article/details/132666851
个人博客主页:https://blog.csdn.net/alicema1111?type=blog
博主所有文章点这里:https://blog.csdn.net/alicema1111?type=blog
博主推荐:
Python人脸识别考勤打卡系统:
https://blog.csdn.net/alicema1111/article/details/133434445
Python果树水果识别:https://blog.csdn.net/alicema1111/article/details/130862842
Python+Yolov8+Deepsort入口人流量统计:https://blog.csdn.net/alicema1111/article/details/130454430
Python+Qt人脸识别门禁管理系统:https://blog.csdn.net/alicema1111/article/details/130353433
Python+Qt指纹录入识别考勤系统:https://blog.csdn.net/alicema1111/article/details/129338432
Python Yolov5火焰烟雾识别源码分享:https://blog.csdn.net/alicema1111/article/details/128420453
Python+Yolov8路面桥梁墙体裂缝识别:https://blog.csdn.net/alicema1111/article/details/133434445
Python+Yolov5道路障碍物识别:https://blog.csdn.net/alicema1111/article/details/129589741
Python+Yolov5跌倒检测 摔倒检测 人物目标行为 人体特征识别:https://blog.csdn.net/alicema1111/article/details/129272048