Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Edge-to-cloud video processing
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
Service Desk
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
STACK-RESEARCH-GROUP
Software
Edge-to-cloud video processing
Commits
98f4235d
Commit
98f4235d
authored
1 week ago
by
MOLLI Martin
Browse files
Options
Downloads
Patches
Plain Diff
Change metrics
parent
45d59dbb
No related branches found
No related tags found
No related merge requests found
Pipeline
#1140339
passed
1 week ago
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
build.sh
+17
-0
17 additions, 0 deletions
build.sh
services/camera/src/camera.py
+18
-10
18 additions, 10 deletions
services/camera/src/camera.py
with
35 additions
and
10 deletions
build.sh
0 → 100644
+
17
−
0
View file @
98f4235d
#!/bin/bash
# Step 2: Build Docker images locally
echo
"Building Docker images for services..."
# Build images for camera, motion_detector, and object_recognizer
docker build
-t
camera:latest ./services/camera
docker build
-t
motion_detector:latest ./services/motion_detector
docker build
-t
object_recognizer:latest ./services/object_recognizer
# Step 4: Set up docker-compose for deployment
echo
"Navigating to deployment directory..."
cd
deploy/docker-compose
||
exit
# Optional: Stop and remove existing containers and volumes (if any)
echo
"Stopping and removing existing containers..."
docker-compose down
--volumes
--remove-orphans
This diff is collapsed.
Click to expand it.
services/camera/src/camera.py
+
18
−
10
View file @
98f4235d
import
random
import
socket
from
contextlib
import
contextmanager
import
cv2
import
pickle
import
struct
...
...
@@ -13,6 +15,15 @@ import imutils # pip install imutils
import
logging
from
opentelemetry.propagate
import
inject
@contextmanager
def
videocapture
(
*
args
,
**
kwargs
):
cap
=
cv2
.
VideoCapture
(
*
args
,
**
kwargs
)
try
:
yield
cap
finally
:
cap
.
release
()
# Configure logging
logging
.
basicConfig
(
format
=
'
%(asctime)s - %(levelname)s - %(message)s
'
,
...
...
@@ -23,14 +34,14 @@ logging.basicConfig(
]
)
frametime_histogram
=
meter
.
create_
histogram
(
frametime_histogram
=
meter
.
create_
gauge
(
name
=
"
camera_frame_time
"
,
description
=
"
Frames time
"
,
unit
=
"
ms
"
)
sleep_time_between_frame
=
meter
.
create_
histogram
(
name
=
"
sleep_time_between_frame
"
,
sleep_time_between_frame
=
meter
.
create_
gauge
(
name
=
"
camera_
sleep_time_between_frame
"
,
description
=
"
sleep_time_between_frame
"
,
unit
=
"
ms
"
)
...
...
@@ -79,9 +90,6 @@ def generate_random_intervals(events_per_hour):
def
main
():
#Connect to motion detector and stream video
while
True
:
client_socket
=
create_socket_and_connect
(
host_ip
,
port
)
...
...
@@ -125,7 +133,7 @@ def stream_video_clip(client_socket: socket):
# Open the appropriate video file
video_path
=
with_animal_video
if
motion
else
no_animal_video
with
cv2
.
V
ideo
C
apture
(
video_path
)
as
video_capture
:
with
v
ideo
c
apture
(
video_path
)
as
video_capture
:
# Determine the number of frames to process according to the clip length
if
motion
:
...
...
@@ -148,7 +156,7 @@ def stream_video_clip(client_socket: socket):
video_capture
.
set
(
cv2
.
CAP_PROP_POS_FRAMES
,
0
)
# Reload video
continue
else
:
logging
.
info
(
f
"
Motion frames processe
d:
{
frame_number
}
"
)
logging
.
info
(
f
"
Frames rea
d:
{
frame_number
}
"
)
break
# Resize frame for consistent processing
...
...
@@ -169,12 +177,12 @@ def stream_video_clip(client_socket: socket):
#Metric logging
frametime
=
time
.
time
()
-
app_start_time
frametime_histogram
.
record
(
frametime
)
frametime_histogram
.
set
(
frametime
)
#Sleep if needed to maintain frame rate
elapsed_time
=
time
.
time
()
-
frame_beginning_time
sleep_time
=
MIN_FRAME_TIME
-
elapsed_time
sleep_time_between_frame
.
record
(
sleep_time
)
sleep_time_between_frame
.
set
(
sleep_time
)
time
.
sleep
(
max
(
0.0
,
sleep_time
))
except
Exception
as
error
:
logging
.
error
(
f
"
Error sending frame:
{
error
}
"
)
...
...
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