Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Агаджанян Руслана Геннадьевна
HW CompGraphics
Commits
5a696911
Commit
5a696911
authored
6 months ago
by
Агаджанян Руслана Геннадьевна
Browse files
Options
Download
Patches
Plain Diff
Код
parents
master
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
interface.py
+161
-0
interface.py
with
161 additions
and
0 deletions
+161
-0
interface.py
0 → 100644
+
161
−
0
View file @
5a696911
import
sys
import
shutil
import
cv2
from
PyQt5
import
QtWidgets
,
QtGui
,
QtCore
from
PyQt5.QtWidgets
import
QFileDialog
,
QColorDialog
,
QSlider
,
QLabel
,
QPushButton
,
QVBoxLayout
,
QWidget
from
video_processing
import
VideoProcessingThread
class
FocusPeakingApp
(
QWidget
):
def
__init__
(
self
):
super
().
__init__
()
self
.
setWindowTitle
(
"Подсветка контуров фокусировки"
)
self
.
setGeometry
(
200
,
200
,
800
,
600
)
self
.
color_rgb
=
(
0
,
255
,
0
)
# Зеленый цвет по умолчанию (RGB)
self
.
color_bgr
=
(
0
,
255
,
0
)
# Зеленый цвет по умолчанию (BGR)
self
.
thickness
=
2
# Толщина по умолчанию
self
.
video_path
=
""
self
.
output_video_path
=
""
self
.
is_processing
=
False
# Флаг для обработки
self
.
video_thread
=
None
# Поток для обработки видео
self
.
setStyleSheet
(
"""
QWidget {
background-color: #2e004d;
color: white;
}
QPushButton {
background-color: #800080;
color: white;
border-radius: 10px;
padding: 5px;
}
QPushButton:hover {
background-color: #a020f0;
}
QLabel {
font-size: 14px;
}
QSlider::groove:horizontal {
background: #bbaaff; /* Светло-фиолетовый цвет полосы */
height: 10px;
border-radius: 5px;
}
QSlider::handle:horizontal {
background-color: #a020f0;
width: 15px;
margin: -5px 0; /* Центрирование ползунка */
border-radius: 7px;
}
"""
)
self
.
select_video_btn
=
QPushButton
(
"Выбрать видео"
,
self
)
self
.
select_video_btn
.
clicked
.
connect
(
self
.
open_file_dialog
)
self
.
video_label
=
QLabel
(
"Видео не выбрано"
,
self
)
self
.
video_label
.
setAlignment
(
QtCore
.
Qt
.
AlignCenter
)
self
.
select_color_btn
=
QPushButton
(
"Выбрать цвет"
,
self
)
self
.
select_color_btn
.
clicked
.
connect
(
self
.
open_color_dialog
)
self
.
color_label
=
QLabel
(
f
"Цвет:
{
self
.
color_rgb
}
"
,
self
)
self
.
color_label
.
setAlignment
(
QtCore
.
Qt
.
AlignCenter
)
self
.
thickness_slider
=
QSlider
(
QtCore
.
Qt
.
Horizontal
,
self
)
self
.
thickness_slider
.
setMinimum
(
1
)
self
.
thickness_slider
.
setMaximum
(
10
)
self
.
thickness_slider
.
setValue
(
self
.
thickness
)
self
.
thickness_slider
.
valueChanged
.
connect
(
self
.
update_thickness
)
self
.
thickness_label
=
QLabel
(
f
"Толщина:
{
self
.
thickness
}
"
,
self
)
self
.
thickness_label
.
setAlignment
(
QtCore
.
Qt
.
AlignCenter
)
self
.
process_btn
=
QPushButton
(
"Запустить обработку"
,
self
)
self
.
process_btn
.
clicked
.
connect
(
self
.
process_video
)
self
.
stop_btn
=
QPushButton
(
"Завершить просмотр"
,
self
)
self
.
stop_btn
.
clicked
.
connect
(
self
.
stop_processing
)
self
.
save_btn
=
QPushButton
(
"Скачать обработанное видео"
,
self
)
self
.
save_btn
.
clicked
.
connect
(
self
.
save_processed_video
)
self
.
display_label
=
QLabel
(
self
)
self
.
display_label
.
setFixedSize
(
640
,
480
)
self
.
display_label
.
setAlignment
(
QtCore
.
Qt
.
AlignCenter
)
layout
=
QVBoxLayout
()
layout
.
addWidget
(
self
.
select_video_btn
)
layout
.
addWidget
(
self
.
video_label
)
layout
.
addWidget
(
self
.
select_color_btn
)
layout
.
addWidget
(
self
.
color_label
)
layout
.
addWidget
(
QLabel
(
"Выберите толщину контура:"
,
self
))
layout
.
addWidget
(
self
.
thickness_slider
)
layout
.
addWidget
(
self
.
thickness_label
)
layout
.
addWidget
(
self
.
process_btn
)
layout
.
addWidget
(
self
.
stop_btn
)
layout
.
addWidget
(
self
.
save_btn
)
layout
.
addWidget
(
self
.
display_label
)
self
.
setLayout
(
layout
)
def
open_file_dialog
(
self
):
options
=
QFileDialog
.
Options
()
file_name
,
_
=
QFileDialog
.
getOpenFileName
(
self
,
"Выберите видеофайл"
,
""
,
"Видео файлы (*.mp4 *.avi)"
)
if
file_name
:
self
.
video_path
=
file_name
self
.
video_label
.
setText
(
f
"Выбрано:
{
file_name
}
"
)
def
open_color_dialog
(
self
):
color
=
QColorDialog
.
getColor
()
if
color
.
isValid
():
self
.
color_rgb
=
(
color
.
red
(),
color
.
green
(),
color
.
blue
())
self
.
color_bgr
=
(
color
.
blue
(),
color
.
green
(),
color
.
red
())
self
.
color_label
.
setText
(
f
"Цвет:
{
self
.
color_rgb
}
"
)
def
update_thickness
(
self
,
value
):
self
.
thickness
=
value
self
.
thickness_label
.
setText
(
f
"Толщина:
{
self
.
thickness
}
"
)
def
process_video
(
self
):
if
not
self
.
video_path
:
QtWidgets
.
QMessageBox
.
warning
(
self
,
"Ошибка"
,
"Пожалуйста, выберите видеофайл для обработки."
)
return
self
.
video_thread
=
VideoProcessingThread
(
self
.
video_path
,
self
.
color_bgr
,
self
.
thickness
)
self
.
video_thread
.
frame_processed
.
connect
(
self
.
show_frame
)
self
.
video_thread
.
finished
.
connect
(
self
.
on_processing_finished
)
self
.
video_thread
.
start
()
def
show_frame
(
self
,
frame
):
rgb_image
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2RGB
)
h
,
w
,
ch
=
rgb_image
.
shape
bytes_per_line
=
ch
*
w
qt_image
=
QtGui
.
QImage
(
rgb_image
.
data
,
w
,
h
,
bytes_per_line
,
QtGui
.
QImage
.
Format_RGB888
)
pixmap
=
QtGui
.
QPixmap
.
fromImage
(
qt_image
)
self
.
display_label
.
setPixmap
(
pixmap
.
scaled
(
self
.
display_label
.
size
(),
QtCore
.
Qt
.
KeepAspectRatio
))
def
stop_processing
(
self
):
if
self
.
video_thread
and
self
.
video_thread
.
isRunning
():
self
.
video_thread
.
stop
()
def
on_processing_finished
(
self
):
self
.
video_thread
=
None
QtWidgets
.
QMessageBox
.
information
(
self
,
"Обработка завершена"
,
"Видео обработано!"
)
def
save_processed_video
(
self
):
options
=
QFileDialog
.
Options
()
save_path
,
_
=
QFileDialog
.
getSaveFileName
(
self
,
"Сохранить видео как"
,
""
,
"Видео файлы (*.mp4 *.avi)"
,
options
=
options
)
if
save_path
:
try
:
shutil
.
copy
(
'output_video.mp4'
,
save_path
)
QtWidgets
.
QMessageBox
.
information
(
self
,
"Успех"
,
f
"Видео успешно сохранено как
{
save_path
}
."
)
except
Exception
as
e
:
QtWidgets
.
QMessageBox
.
warning
(
self
,
"Ошибка"
,
f
"Не удалось сохранить видео:
{
str
(
e
)
}
"
)
if
__name__
==
"__main__"
:
app
=
QtWidgets
.
QApplication
(
sys
.
argv
)
window
=
FocusPeakingApp
()
window
.
show
()
sys
.
exit
(
app
.
exec_
())
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets