def click_pushButton_3(self): # 点击 pushButton_3 触发 框选图像 print("pushButton_3") self.label_1.setGeometry(QRect(20, 20, 400, 320)) hImg, wImg = self.img1.shape[:2] wLabel = self.label_1.width() hLabel = self.label_1.height() x0 = self.label_1.x0 * wImg // wLabel y0 = self.label_1.y0 * hImg // hLabel x1 = self.label_1.x1 * wImg // wLabel y1 = self.label_1.y1 * hImg // hLabel print("hImg,wImg=({},{}), x1,y1=({},{})".format(hImg, wImg, hLabel, wLabel)) print("x0,y0=({},{}), x1,y1=({},{})".format(x0, y0, x1, y1)) self.img2 = np.zeros((self.img1.shape), np.uint8) self.img2[y0:y1, x0:x1, :] = self.img1[y0:y1, x0:x1, :] print(self.img2.shape) self.refreshShow(self.img2, self.label_2) # 刷新显示 return 为什么我框选的图像没有在正中心

时间: 2024-04-27 12:24:50 浏览: 5
可能是因为 `self.label_1.setGeometry(QRect(20, 20, 400, 320))` 语句将 label_1 的位置设置为左上角坐标为 (20,20),大小为 400x320,而不是将其放置在中心位置。你可以尝试将该语句修改为 `self.label_1.setGeometry(QRect(0, 0, 400, 320))`,将其放置在中心位置。另外,你也可以通过计算 label_1 的位置将其放置在中心位置。
相关问题

@pyqtSlot() def on_pushButton_clicked(self): 槽函数可以用这样的形式来写吗

是的,你可以使用`@pyqtSlot()`装饰器来定义槽函数。这种形式的槽函数定义是Qt的一种推荐方式,特别是当你在Qt Designer中使用UI文件时,它可以帮助确保正确的信号与槽的连接。 以下是一个示例,展示了如何使用`@pyqtSlot()`装饰器定义槽函数: ```python from PyQt5.QtCore import pyqtSlot from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton class MyWindow(QMainWindow): def __init__(self): super().__init__() self.button = QPushButton('Click me') self.button.clicked.connect(self.on_button_clicked) @pyqtSlot() def on_button_clicked(self): # 在这里编写按钮点击后要执行的代码 print('Button clicked!') if __name__ == '__main__': app = QApplication([]) window = MyWindow() window.show() app.exec_() ``` 在这个示例中,`on_button_clicked`方法被使用`@pyqtSlot()`装饰器修饰,表示它是一个槽函数。当按钮被点击时,`on_button_clicked`方法会被调用,输出"Button clicked!"。 注意,使用`@pyqtSlot()`装饰器是可选的。如果你没有使用装饰器,槽函数的定义也是有效的。但是,在某些情况下(如使用UI文件),使用装饰器可以帮助确保正确的信号与槽连接。

self.pushButton_show3D.clicked.connect(self.show_3D)多线程

如果你需要在点击 `pushButton_show3D` 按钮后启动一个耗时的任务,可以使用多线程来避免阻塞主线程。以下是一个简单的例子: ```python from PyQt5.QtCore import QThread, pyqtSignal class TaskThread(QThread): finished = pyqtSignal(object) def __init__(self): super().__init__() def run(self): # 在这里执行耗时的任务 result = compute_3D_data() # 发送任务完成的信号,将结果传递给主线程 self.finished.emit(result) ``` 在主窗口中,你需要将 `TaskThread` 实例化并连接到按钮的 `clicked` 信号上: ```python self.thread = TaskThread() self.thread.finished.connect(self.show_3D) self.pushButton_show3D.clicked.connect(self.thread.start) ``` 在 `TaskThread` 的 `run` 方法中执行的任务会在一个独立的线程中运行,不会阻塞主线程。当任务完成后,会发送一个 `finished` 信号,将结果传递给 `show_3D` 方法,该方法会在主线程中执行,用于更新UI界面。

相关推荐

这段代码没进 thing1()的原因 class Worker(QtCore.QThread): sinOut = pyqtSignal(str) def __init__(self, parent=None): super(Worker, self).__init__(parent) # 设置工作状态与初始num数值 self.working = True self.num = 0 #def __del__(self): # 线程状态改变与线程终止 #self.working = False #self.wait() def stop(self): #线程状态改变与线程终止 self.working = False self.wait() def run(self): self.working = True while self.working == True: #file_str = 'File index{0}'.format(self.num) self.num += 1 # 发射信号 #self.sinOut.emit(file_str) self.sinOut.emit('1') # 线程休眠2秒 self.msleep(5) class parentWindow(QMainWindow): def __init__(self): QMainWindow.__init__(self) self.main_ui = JQ.Ui_MainWindow() self.main_ui.setupUi(self) self.thread1 = Worker() self.main_ui.pushButton_2.clicked.connect(self.thing1) self.thread1.sinOut.connect(self.printt) def thing1(self): #self.main_ui.pushButton.setEnabled(False) print('9999999999') self.thread1.start() self.thread1.wait() print('123') #self.sleep(2) def printt(self): print('7777') def ok(): print('ok') # def hourstest(): # thread1 = Worker() # thread1.start() # com = JQ.Ui_MainWindow().comboBox_2.currentText() # ser = serial.Serial('com3', 1200, timeout=1) # data = bytes.fromhex( # '68 01 00 20 00 00 00 00 00 34 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 33 F4 16 ') # ser.write(data) if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) widget = QtWidgets.QMainWindow() widget = parentWindow() ui = JQ.Ui_MainWindow() # 这是原py中的类,因人而异哦 ui.setupUi(widget) ui.discoverSerial() #串口发现 #ui.pushButton_2.clicked.connect(widget.thing1) widget.show() sys.exit(app.exec_())

这段代码的pushButton_2 为什么触发不了线程 class Worker(QtCore.QThread): sinOut = pyqtSignal(str) def __init__(self, parent=None): super(Worker, self).__init__(parent) # 设置工作状态与初始num数值 self.working = True self.num = 0 #def __del__(self): # 线程状态改变与线程终止 #self.working = False #self.wait() def stop(self): #线程状态改变与线程终止 self.working = False self.wait() def run(self): self.working = True while self.working == True: #file_str = 'File index{0}'.format(self.num) self.num += 1 # 发射信号 #self.sinOut.emit(file_str) self.sinOut.emit('1') # 线程休眠2秒 self.msleep(5) class parentWindow(QMainWindow): def __init__(self): QMainWindow.__init__(self) self.main_ui = JQ.Ui_MainWindow() self.main_ui.setupUi(self) self.thread1 = Worker() self.main_ui.pushButton_2.clicked.connect(self.thing1) self.thread1.sinOut.connect(self.printt) def thing1(self): #self.main_ui.pushButton.setEnabled(False) print('9999999999') self.thread1.start() print('123') #self.sleep(2) def printt(self): print('7777') def ok(): print('ok') # def hourstest(): # thread1 = Worker() # thread1.start() # com = JQ.Ui_MainWindow().comboBox_2.currentText() # ser = serial.Serial('com3', 1200, timeout=1) # data = bytes.fromhex( # '68 01 00 20 00 00 00 00 00 34 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 33 F4 16 ') # ser.write(data) if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) widget = QtWidgets.QMainWindow() widget = parentWindow() ui = JQ.Ui_MainWindow() # 这是原py中的类,因人而异哦 ui.setupUi(widget) ui.discoverSerial() #串口发现 #ui.pushButton_2.clicked.connect(widget.thing1) widget.show() sys.exit(app.exec_())

import sys from PyQt5.QtWidgets import QApplication, QWidget , QMainWindow from Calui1 import Ui_Form class Mywindow(QWidget,Ui_Form): def __init__(self): super(Mywindow,self).__init__() self.setupUi(self) def btnClear_clicked(self): self.lineEdit.clear() def btn1(self): self.lineEdit.insert("1") def btn2(self): self.lineEdit.insert("2") def btn3(self): self.lineEdit.insert("3") def btn4(self): self.lineEdit.insert("4") def btn5(self): self.lineEdit.insert("5") def btn6(self): self.lineEdit.insert("6") def btn7(self): self.lineEdit.insert("7") def btn8(self): self.lineEdit.insert("8") def btn9(self): self.lineEdit.insert("9") def btn0(self): self.lineEdit.insert("0") def btn_plus(self): self.lineEdit.insert("+") def btn_sub(self): self.lineEdit.insert("-") def btn_mul(self): self.lineEdit.insert("*") def btn_div(self): self.lineEdit.insert("/") def btnequal(self): text=self.lineEdit.text() self.lineEdit.insert("= %.2f" %(eval(text))) if __name__=='__main__': app=QApplication(sys.argv) win=Mywindow() win.pushButton_7.clicked.connect(win.btnClear_clicked()) win.pushButton.clicked.connect(win.btn1()) win.pushButton_2.clicked.connect(win.btn2()) win.pushButton_3.clicked.connect(win.btn3()) win.pushButton_4.clicked.connect(win.btn_plus()) win.pushButton_5.clicked.connect(win.btn4()) win.pushButton_6.clicked.connect(win.btn7()) win.pushButton_8.clicked.connect(win.btn5()) win.pushButton_9.clicked.connect(win.btn8()) win.pushButton_10.clicked.connect(win.btn0()) win.pushButton_11.clicked.connect(win.btn6()) win.pushButton_12.clicked.connect(win.btn9()) win.pushButton_13.clicked.connect(win.btnequal()) win.pushButton_14.clicked.connect(win.btn_sub()) win.pushButton_15.clicked.connect(win.btn_mul()) win.pushButton_16.clicked.connect(win.btn_div()) win.show() sys.exit(app.exec_())错在哪

使用QTimer对象代替QBasicTimer对象,修改程序class MyWindow(QWidget): def init(self): super().init() self.thread_list = [] self.color_photo_dir = os.path.join(os.getcwd(), "color_photos") self.depth_photo_dir = os.path.join(os.getcwd(), "depth_photos") self.image_thread = None self.saved_color_photos = 0 # 定义 saved_color_photos 属性 self.saved_depth_photos = 0 # 定义 saved_depth_photos 属性 self.init_ui() def init_ui(self): self.ui = uic.loadUi("C:/Users/wyt/Desktop/D405界面/intelrealsense1.ui") self.open_btn = self.ui.pushButton self.color_image_chose_btn = self.ui.pushButton_3 self.depth_image_chose_btn = self.ui.pushButton_4 self.open_btn.clicked.connect(self.open) self.color_image_chose_btn.clicked.connect(lambda: self.chose_dir(self.ui.lineEdit, "color")) self.depth_image_chose_btn.clicked.connect(lambda: self.chose_dir(self.ui.lineEdit_2, "depth")) def open(self): self.profile = self.pipeline.start(self.config) self.is_camera_opened = True self.label.setText('相机已打开') self.label.setStyleSheet('color:green') self.open_btn.setEnabled(False) self.close_btn.setEnabled(True) self.image_thread = ImageThread(self.pipeline, self.color_label, self.depth_label, self.interval, self.color_photo_dir, self.depth_photo_dir, self._dgl) self.image_thread.saved_color_photos_signal.connect(self.update_saved_color_photos_label) self.image_thread.saved_depth_photos_signal.connect(self.update_saved_depth_photos_label) self.image_thread.start() def chose_dir(self, line_edit, button_type): my_thread = MyThread(line_edit, button_type) my_thread.finished_signal.connect(self.update_line_edit) self.thread_list.append(my_thread) my_thread.start()

程序运行提示QBasicTimer::stop: Failed. Possibly trying to stop from a different thread,修改程序class MyWindow(QWidget): def init(self): super().init() self.thread_list = [] self.color_photo_dir = os.path.join(os.getcwd(), "color_photos") self.depth_photo_dir = os.path.join(os.getcwd(), "depth_photos") self.image_thread = None self.saved_color_photos = 0 # 定义 saved_color_photos 属性 self.saved_depth_photos = 0 # 定义 saved_depth_photos 属性 self.init_ui() def init_ui(self): self.ui = uic.loadUi("C:/Users/wyt/Desktop/D405界面/intelrealsense1.ui") self.open_btn = self.ui.pushButton self.color_image_chose_btn = self.ui.pushButton_3 self.depth_image_chose_btn = self.ui.pushButton_4 self.open_btn.clicked.connect(self.open) self.color_image_chose_btn.clicked.connect(lambda: self.chose_dir(self.ui.lineEdit, "color")) self.depth_image_chose_btn.clicked.connect(lambda: self.chose_dir(self.ui.lineEdit_2, "depth")) def open(self): self.profile = self.pipeline.start(self.config) self.is_camera_opened = True self.label.setText('相机已打开') self.label.setStyleSheet('color:green') self.open_btn.setEnabled(False) self.close_btn.setEnabled(True) self.image_thread = ImageThread(self.pipeline, self.color_label, self.depth_label, self.interval, self.color_photo_dir, self.depth_photo_dir, self._dgl) self.image_thread.saved_color_photos_signal.connect(self.update_saved_color_photos_label) self.image_thread.saved_depth_photos_signal.connect(self.update_saved_depth_photos_label) self.image_thread.start() def chose_dir(self, line_edit, button_type): my_thread = MyThread(line_edit, button_type) my_thread.finished_signal.connect(self.update_line_edit) self.thread_list.append(my_thread) my_thread.start()

最新推荐

recommend-type

pre_o_1csdn63m9a1bs0e1rr51niuu33e.a

pre_o_1csdn63m9a1bs0e1rr51niuu33e.a
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

2. 通过python绘制y=e-xsin(2πx)图像

可以使用matplotlib库来绘制这个函数的图像。以下是一段示例代码: ```python import numpy as np import matplotlib.pyplot as plt def func(x): return np.exp(-x) * np.sin(2 * np.pi * x) x = np.linspace(0, 5, 500) y = func(x) plt.plot(x, y) plt.xlabel('x') plt.ylabel('y') plt.title('y = e^{-x} sin(2πx)') plt.show() ``` 运行这段
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

实现实时监控告警系统:Kafka与Grafana整合

![实现实时监控告警系统:Kafka与Grafana整合](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9tbWJpei5xcGljLmNuL21tYml6X2pwZy9BVldpY3ladXVDbEZpY1pLWmw2bUVaWXFUcEdLT1VDdkxRSmQxZXB5R1lxaWNlUjA2c0hFek5Qc3FyRktudFF1VDMxQVl3QTRXV2lhSWFRMEFRc0I1cW1ZOGcvNjQw?x-oss-process=image/format,png) # 1.1 Kafka集群架构 Kafka集群由多个称为代理的服务器组成,这
recommend-type

导入numpy库,创建两个包含9个随机数的3*3的矩阵,将两个矩阵分别打印出来,计算两个数组的点积并打印出来。(random.randn()、dot()函数)

可以的,以下是代码实现: ```python import numpy as np # 创建两个包含9个随机数的3*3的矩阵 matrix1 = np.random.randn(3, 3) matrix2 = np.random.randn(3, 3) # 打印两个矩阵 print("Matrix 1:\n", matrix1) print("Matrix 2:\n", matrix2) # 计算两个数组的点积并打印出来 dot_product = np.dot(matrix1, matrix2) print("Dot product:\n", dot_product) ``` 希望
recommend-type

c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf

校园超市商品信息管理系统课程设计旨在帮助学生深入理解程序设计的基础知识,同时锻炼他们的实际操作能力。通过设计和实现一个校园超市商品信息管理系统,学生掌握了如何利用计算机科学与技术知识解决实际问题的能力。在课程设计过程中,学生需要对超市商品和销售员的关系进行有效管理,使系统功能更全面、实用,从而提高用户体验和便利性。 学生在课程设计过程中展现了积极的学习态度和纪律,没有缺勤情况,演示过程流畅且作品具有很强的使用价值。设计报告完整详细,展现了对问题的深入思考和解决能力。在答辩环节中,学生能够自信地回答问题,展示出扎实的专业知识和逻辑思维能力。教师对学生的表现予以肯定,认为学生在课程设计中表现出色,值得称赞。 整个课程设计过程包括平时成绩、报告成绩和演示与答辩成绩三个部分,其中平时表现占比20%,报告成绩占比40%,演示与答辩成绩占比40%。通过这三个部分的综合评定,最终为学生总成绩提供参考。总评分以百分制计算,全面评估学生在课程设计中的各项表现,最终为学生提供综合评价和反馈意见。 通过校园超市商品信息管理系统课程设计,学生不仅提升了对程序设计基础知识的理解与应用能力,同时也增强了团队协作和沟通能力。这一过程旨在培养学生综合运用技术解决问题的能力,为其未来的专业发展打下坚实基础。学生在进行校园超市商品信息管理系统课程设计过程中,不仅获得了理论知识的提升,同时也锻炼了实践能力和创新思维,为其未来的职业发展奠定了坚实基础。 校园超市商品信息管理系统课程设计的目的在于促进学生对程序设计基础知识的深入理解与掌握,同时培养学生解决实际问题的能力。通过对系统功能和用户需求的全面考量,学生设计了一个实用、高效的校园超市商品信息管理系统,为用户提供了更便捷、更高效的管理和使用体验。 综上所述,校园超市商品信息管理系统课程设计是一项旨在提升学生综合能力和实践技能的重要教学活动。通过此次设计,学生不仅深化了对程序设计基础知识的理解,还培养了解决实际问题的能力和团队合作精神。这一过程将为学生未来的专业发展提供坚实基础,使其在实际工作中能够胜任更多挑战。