Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 81dee24d authored by sidi mohammed kaddour's avatar sidi mohammed kaddour
Browse files

fixed bugs

parent 7205b544
No related branches found
No related tags found
No related merge requests found
......@@ -4,28 +4,28 @@
echo "Building Docker images for services..."
# Build images for camera, motion_detector, and object_recognizer
docker build -t camera:latest --platform linux/amd64 ./services/camera
docker build -t motion_detector:latest --platform linux/amd64 ./services/motion_detector
docker build -t object_recognizer:latest --platform linux/amd64 ./services/object_recognizer
sudo docker build -t camera:latest --platform linux/amd64 ./services/camera
sudo docker build -t motion_detector:latest --platform linux/amd64 ./services/motion_detector
sudo docker build -t object_recognizer:latest --platform linux/amd64 ./services/object_recognizer
# Step 3: Optional - Tag and push the images to Docker Hub
# Replace <your-username> with your Docker Hub username
# Tag images for Docker Hub
echo "Tagging images for Docker Hub..."
docker tag camera:latest medkaddour/camera:latest
docker tag motion_detector:latest medkaddour/motion_detector:latest
docker tag object_recognizer:latest medkaddour/object_recognizer:latest
sudo docker tag camera:latest medkaddour/camera:latest
sudo docker tag motion_detector:latest medkaddour/motion_detector:latest
sudo docker tag object_recognizer:latest medkaddour/object_recognizer:latest
# Log in to Docker Hub
echo "Logging into Docker Hub..."
docker login
sudo docker login
# Push images to Docker Hub
echo "Pushing images to Docker Hub..."
docker push medkaddour/camera:latest
docker push medkaddour/motion_detector:latest
docker push medkaddour/object_recognizer:latest
sudo docker push medkaddour/camera:latest
sudo docker push medkaddour/motion_detector:latest
sudo docker push medkaddour/object_recognizer:latest
# Step 4: Set up docker-compose for deployment
echo "Navigating to deployment directory..."
......
......@@ -97,66 +97,67 @@ def main():
if client_socket:
while True:
for interval in generate_random_intervals(appearance_rate):
interval_frame_count = interval * 30
frame_number = 0
if motion:
vid = cv2.VideoCapture(with_animal_video)
motion = False
else:
vid = cv2.VideoCapture(no_animal_video)
motion = True
logging.info(f"Motion: {motion}")
while (frame_number < interval_frame_count) or (not motion):
frame_number += 1
carrier = {}
with tracer.start_as_current_span("sending frame from camera") as span:
try:
inject(carrier)
img, frame = vid.read()
if not img:
if motion:
vid = cv2.VideoCapture(no_animal_video)
continue
else:
logging.info(f"Motion frames count: {frame_number}")
break
frame = imutils.resize(frame, width=640)
start_time = time.time()
current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
data = {
'frame': frame,
'capture_time': current_time,
'carrier': carrier
}
a = pickle.dumps(data)
message = struct.pack("Q", len(a)) + a
client_socket.sendall(message)
# Update FPS calculation
fps_frame_count += 1
elapsed_time = time.time() - fps_start_time
if elapsed_time >= 10.0:
fps = round(fps_frame_count / elapsed_time, 2)
logging.info(f"FPS: {fps} (Total frames: {fps_frame_count}, Time: {elapsed_time})")
fps_histo.record(fps)
fps_count.set(fps)
fps_frame_count = 0
fps_start_time = time.time()
# Maintain the frame rate
end_time = time.time()
elapsed_time = end_time - start_time
if elapsed_time < frame_interval:
time.sleep(0.025) # frame_interval - elapsed_time
except Exception as e:
logging.error(f"Error sending frame: {e}")
client_socket.close()
break
for motion in (False, True):
frame_number = 0
if motion:
vid = cv2.VideoCapture(with_animal_video)
interval_frame_count= int(vid.get(cv2.CAP_PROP_FRAME_COUNT))
else:
vid = cv2.VideoCapture(no_animal_video)
interval_frame_count = interval * 30
logging.info(f"Motion: {motion} max frame count: {interval_frame_count}")
while (frame_number < interval_frame_count):
frame_number += 1
carrier = {}
with tracer.start_as_current_span("sending frame from camera") as span:
try:
inject(carrier)
img, frame = vid.read()
if not img:
if motion:
vid = cv2.VideoCapture(no_animal_video)
continue
else:
logging.info(f"Motion frames count: {frame_number}")
break
frame = imutils.resize(frame, width=640)
start_time = time.time()
current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
data = {
'frame': frame,
'capture_time': current_time,
'carrier': carrier
}
a = pickle.dumps(data)
message = struct.pack("Q", len(a)) + a
client_socket.sendall(message)
# Update FPS calculation
fps_frame_count += 1
elapsed_time = time.time() - fps_start_time
if elapsed_time >= 10.0:
fps = round(fps_frame_count / elapsed_time, 2)
logging.info(f"FPS: {fps} (Total frames: {fps_frame_count}, Time: {elapsed_time})")
fps_histo.record(fps)
fps_count.set(fps)
fps_frame_count = 0
fps_start_time = time.time()
# Maintain the frame rate
end_time = time.time()
elapsed_time = end_time - start_time
if elapsed_time < frame_interval:
time.sleep(0.025) # frame_interval - elapsed_time
except Exception as e:
logging.error(f"Error sending frame: {e}")
client_socket.close()
break
if __name__ == "__main__":
......
......@@ -100,6 +100,11 @@ def process_frames(addr, frame_queue, or_host_ip, or_port):
name="md_detected_motion",
description="Detected motions 1 or 0",
)
md_detected_motion_nbr = meter.create_gauge(
name="md_detected_motion_nbr",
description="number of detected motions from the starting of the service",
)
md_detected_motion_nbr_rec=0
fps_start_time = time.time()
while True:
try:
......@@ -159,7 +164,8 @@ def process_frames(addr, frame_queue, or_host_ip, or_port):
text = "md: motion detected"
if detected:
logging.info("Motion detected, preparing to send frame to Object Recognizer.")
md_detected_motion_nbr_rec += 1
md_detected_motion_nbr.set(md_detected_motion_nbr_rec)
md_detected_motion.set(1)
orclient_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
orclient_socket.connect((or_host_ip, or_port))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment