Browse Source

增加至3监视器,视频源默认从相机读取,可控制刷新

gui
Fiber 4 weeks ago
parent
commit
3c13486c0e
  1. 49
      src/esd_bleeding_view_tool/__init__.py
  2. 75
      src/esd_bleeding_view_tool/core.py

49
src/esd_bleeding_view_tool/__init__.py

@ -1,10 +1,11 @@
import sys
import cv2
import threading
from core import Video, Mark
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QMetaObject, QObject, QPoint, QRect, QTimer,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QAction, QBrush, QColor, QConicalGradient,
QCursor, QFont, QFontDatabase, QGradient,
@ -28,6 +29,10 @@ class Ui_MainWindow(object):
self.pushButton_2.setObjectName(u"pushButton_2")
self.graphicsView = QGraphicsView(self.centralwidget)
self.graphicsView.setObjectName(u"graphicsView")
self.graphicsView_2 = QGraphicsView(self.centralwidget)
self.graphicsView_2.setObjectName(u"graphicsView_2")
self.graphicsView_3 = QGraphicsView(self.centralwidget)
self.graphicsView_3.setObjectName(u"graphicsView_3")
self.textBrowser = QTextBrowser(self.centralwidget)
self.textBrowser.setObjectName(u"textBrowser")
self.pushButton_3 = QPushButton(self.centralwidget)
@ -50,12 +55,14 @@ class Ui_MainWindow(object):
w = w+10
h = h+10
w_button = 80
self.resize(w+w_button*2+30, h+100)
self.resize(2*w+10, h*2+50)
self.graphicsView.setGeometry(QRect(0, 0, w, h))
self.textBrowser.setGeometry(QRect(w+10, 30, w_button*2+10, 200))
self.pushButton.setGeometry(QRect(w+10, 240, w_button*2+10, 50))
self.pushButton_2.setGeometry(QRect(w+10, 300, w_button, 50))
self.pushButton_3.setGeometry(QRect(w+10+w_button+10, 300, w_button, 50))
self.graphicsView_2.setGeometry(QRect(w+10, 0, w, h))
self.graphicsView_3.setGeometry(QRect(0, h+10, w, h))
self.textBrowser.setGeometry(QRect(w+10, h+10+30, w_button*2+10, 200))
self.pushButton.setGeometry(QRect(w+10, h+10+240, w_button*2+10, 50))
self.pushButton_2.setGeometry(QRect(w+10, h+10+300, w_button, 50))
self.pushButton_3.setGeometry(QRect(w+10+w_button+10, h+10+300, w_button, 50))
# self.pushButton_4.setGeometry(QRect(w+10+w_button+10, 560, w_button, 40))
# self.comboBox.setGeometry(QRect(w+10+w_button+10, 530, w_button, 30))
@ -70,6 +77,9 @@ class Ui_MainWindow(object):
# ui逻辑控制
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self):
self.timer_interval = 1000
self.max_width = 460
super(MainWindow, self).__init__()
self.setupUi(self)
@ -80,21 +90,28 @@ class MainWindow(QMainWindow, Ui_MainWindow):
# self.comboBox.currentIndexChanged.connect(self.name_reset)
self.video = Video()
self.timer = QTimer()
self.timer.timeout.connect(self.timer_act)
self.scene = QGraphicsScene()
self.graphicsView.setScene(self.scene)
self.graphicsView.show()
self.txt = ""
def show_video(self):
img = self.video.read() # 读入opencv视频流
def show_video(self, img = None):
if img is None:
img = self.video.read() # 读入opencv视频流
y, x = img.shape[:-1]
#视频帧如果过大需要在此进行缩放,如
max_width = 1000
if x > max_width:
mult = max_width/x
if x > self.max_width:
mult = self.max_width/x
img = cv2.resize(img, (0, 0), fx=mult, fy=mult, interpolation=cv2.INTER_NEAREST)
y, x = img.shape[:-1]
@ -115,11 +132,16 @@ class MainWindow(QMainWindow, Ui_MainWindow):
def start(self):
## 调用start函数
self.load_video()
self.timer.start(self.timer_interval)
self.show_text("started\n")
def test(self):
print("test func run")
def pause(self):
## 调用pause函数
self.timer.stop()
self.show_text("paused\n")
def load_video(self):
@ -135,6 +157,9 @@ class MainWindow(QMainWindow, Ui_MainWindow):
return
self.show_text("loaded model "+fname+"\n")
def timer_act(self):
self.show_video()
# def name_reset(self):
# name = self.comboBox.currentText()
# self.mark.change_name(name)

75
src/esd_bleeding_view_tool/core.py

@ -3,7 +3,9 @@ import cv2
import pandas as pd
import re
import numpy as np
import time
import math
import threading
interval = 30
@ -25,33 +27,85 @@ def convert_video(videoname):
else:
print('视频打开失败!')
class Mark:
def __init__(self, mark_dir):
self.df_source = pd.read_excel(mark_dir, sheet_name=None)
self.sheet = list(self.df_source.keys())
self.df = self.df_source[self.sheet[0]]
col_name = self.df.columns.tolist()
self.method = col_name[1:]
self.frame = self.df.loc[:,col_name[0]]
self.total_frame = len(self.frame)
def read(self, number):
line = self.df.loc[number,:]
rt = re.findall(r'\d+', line.iloc[0])
if len(rt) > 0:
return (int(rt[0]), line[self.method[0]:])
else:
return None
def max_frame(self):
return self.total_frame
def sheet_list(self):
return self.sheet
def get_method(self, raw):
method = []
NaN = pd.isnull(raw)
for i in range(len(raw)):
if not NaN.iloc[i]:
method.append(self.method[i])
return method
def change_name(self, name):
if name in self.sheet:
self.df = self.df_source[name]
col_name = self.df.columns.tolist()
self.frame = self.df.loc[:,col_name[0]]
self.total_frame = len(self.frame)
class Video:
def __init__(self, video_dir, buffer_num_max = 3):
self.video_dir = video_dir
def __init__(self, video_dir=0, buffer_num_max = 3):
capture = cv2.VideoCapture(video_dir)
if capture.isOpened():
self.total_frames = int(capture.get(cv2.CAP_PROP_FRAME_COUNT))
if video_dir != 0:
self.total_frames = int(capture.get(cv2.CAP_PROP_FRAME_COUNT))
self.fps = 0
else:
self.total_frames = 0
self.fps = capture.get(cv2.CAP_PROP_FPS)
self.video = capture
else:
self.video = None
self.frame_num = 0
#buffer init
self.buffer = [None for _ in range(3)]
self.buffer = []
self.buffer_num = 0
self.buffer_num_max = buffer_num_max
def read(self): ##测试用,从视频文件读取
cap = self.video
cap.set(cv2.CAP_PROP_POS_FRAMES, self.frame_num)
ret, img=cap.read()
if ret:
self.update_buffer(img)
self.frame_num += 1
return img
else:
return None
def set_video_loop(self, show_video): ####
self.show_video_func = show_video
def video_loop(self):
ret, img=self.video.read()
if ret:
self.update_buffer(img)
self.show_video_func(img)
print("read")
def get_and_skip_frame(self, skip_num=29): #抽帧
img = self.read()
for _ in range(skip_num):
@ -59,8 +113,11 @@ class Video:
return img
def update_buffer(self, img): #更新buffer
self.buffer[self.buffer_num] = img
self.buffer_num = (self.buffer_num + 1) % self.buffer_num_max
self.buffer.append(img)
if self.buffer_num < self.buffer_num_max:
self.buffer_num += 1
else:
self.buffer.pop(0)
def get_buffer(self): #获取buffer内容
return self.buffer

Loading…
Cancel
Save