Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Module 4
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Service
Module 4
Commits
84825d7a
Commit
84825d7a
authored
10 months ago
by
DMIbragimov
Browse files
Options
Downloads
Patches
Plain Diff
Update app.py
parent
e701acd2
No related branches found
Branches containing commit
No related tags found
1 merge request
!1
Add new directory
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
kontur/web/app.py
+21
-0
21 additions, 0 deletions
kontur/web/app.py
with
21 additions
and
0 deletions
kontur/web/app.py
+
21
−
0
View file @
84825d7a
...
...
@@ -11,6 +11,8 @@ from PyQt5.QtCore import Qt, pyqtSlot
from
PyQt5.QtWebEngineWidgets
import
QWebEngineView
from
PyQt5.QtGui
import
QImage
,
QPixmap
from
qasync
import
QEventLoop
,
asyncSlot
from
ultralytics
import
YOLO
import
os
# Настройка логирования
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
...
...
@@ -21,6 +23,10 @@ class MainWindow(QWidget):
super
().
__init__
()
self
.
initUI
()
# Инициализация модели YOLO
self
.
model
=
YOLO
(
'
models/yolov8n.pt
'
)
self
.
model
.
conf
=
0.5
# Установка порога уверенности для детекции
def
initUI
(
self
):
self
.
setWindowTitle
(
'
Multi-Input PyQt Application
'
)
self
.
setGeometry
(
100
,
100
,
1920
,
1080
)
...
...
@@ -116,6 +122,11 @@ class MainWindow(QWidget):
if
not
ret
:
logger
.
error
(
"
Failed to read frame from RTSP stream
"
)
break
# Применение модели YOLO к кадру
results
=
self
.
model
.
predict
(
frame
,
conf
=
0.6
)
frame
=
self
.
draw_detections
(
frame
,
results
)
# Convert the frame to QImage
frame_rgb
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_BGR2RGB
)
height
,
width
,
channel
=
frame_rgb
.
shape
...
...
@@ -176,6 +187,16 @@ class MainWindow(QWidget):
self
.
telemetry_label
.
setText
(
f
"
Telemetry Data:
{
telemetry_info
}
"
)
logger
.
debug
(
"
Telemetry data updated
"
)
def
draw_detections
(
self
,
frame
,
results
):
for
r
in
results
:
for
i
,
c
in
enumerate
(
r
.
boxes
.
cls
):
if
r
.
boxes
.
conf
[
i
]
>
0.5
:
x1
,
y1
,
x2
,
y2
=
r
.
boxes
.
xyxy
[
i
]
# Координаты рамок
cv2
.
rectangle
(
frame
,
(
int
(
x1
),
int
(
y1
)),
(
int
(
x2
),
int
(
y2
)),
(
0
,
255
,
0
),
2
)
# Рисование рамки
label
=
f
"
{
self
.
model
.
names
[
int
(
c
)]
}
{
r
.
boxes
.
conf
[
i
]
:
.
2
f
}
"
cv2
.
putText
(
frame
,
label
,
(
int
(
x1
),
int
(
y1
-
10
)),
cv2
.
FONT_HERSHEY_SIMPLEX
,
0.5
,
(
0
,
255
,
0
),
2
)
return
frame
def
dark_theme_stylesheet
(
self
):
return
"""
QWidget {
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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