代码拉取完成,页面将自动刷新
import time
from threading import Thread
from PyQt5.QtCore import QSize, Qt
from PyQt5.QtGui import QImage, QPixmap
# pickle QPixmap
class ThreadOpencvToQpixmap(Thread):
def __init__(self, my_thread_queue_image_done, my_process_queue_image_processed, my_end):
super(ThreadOpencvToQpixmap, self).__init__()
self.my_thread_queue_image_done = my_thread_queue_image_done
self.my_process_queue_image_processed = my_process_queue_image_processed
self.my_end = my_end
self.is_running = True
self.w = 960
self.h = 540
def run(self) -> None:
time.sleep(0.5)
while self.is_running:
flag = self.function()
if not flag:
time.sleep(0.0015)
def stop(self):
self.is_running = False
def function(self):
if self.my_process_queue_image_processed.empty():
if not self.my_end.empty():
self.is_running = False
return False
else:
frame, image, data = self.my_process_queue_image_processed.get()
size = QSize(self.w, self.h)
image = QImage(image.data.tobytes(), image.shape[1], image.shape[0], image.shape[1] * 3,
QImage.Format_RGB888)
image = QPixmap.fromImage(image.scaled(size, Qt.IgnoreAspectRatio))
self.my_thread_queue_image_done.put([frame, image, data])
return True
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。