Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glydric #19

Merged
merged 5 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Backend/src/app/machineLearning/machineLearning.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ export class MachineLearningController {
) {
const date = new Date();

console.log('Adding data to database');
// console.log('Adding data to database');
await this.database.addData(new DataType(cameraId, date, null, file));
console.log('Sending intrusion detection notification');
// console.log('Sending intrusion detection notification');
await this.telegramApi.sendIntrusionDetectionNotification(
cameraId,
date,
Expand Down
1 change: 0 additions & 1 deletion Backend/src/telegram/telegram.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import * as TelegramBot from 'node-telegram-bot-api';
import * as process from 'process';
import { DatabaseService } from '../database/database.service';
import UserDTO from '../user.dto';
import { JwtService } from '@nestjs/jwt';
import * as bcrypt from 'bcrypt';

@Injectable()
Expand Down
13 changes: 3 additions & 10 deletions ImageRecognition/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,11 @@
initBufferSize(MAX)

with concurrent.futures.ThreadPoolExecutor() as executor:
# args: (int, int) = [(i, i) for i in range(0, 8)]
args: (int, int) = [(i, i) for i in range(2, 4)]
args: (int, int) = [(i, i) for i in range(0, MAX)]
# args: (int, int) = [(i, i) for i in range(0, 1)]

results = [executor.submit(detection, *arg) for arg in args]
concurrent.futures.wait(results)


# example
# cam1 = "rtsp://192.168.1.41:80/ch0_0.264"
# cam2 = "rtsp://192.168.1.41:80/ch1_0.264"
# cam3 = "rtsp://192.168.1.41:80/ch2_0.264"
# cam4 = "rtsp://192.168.1.41:80/ch3_0.264"
# cam5 = "rtsp://192.168.1.41:80/ch4_0.264"
# cam6 = "rtsp://192.168.1.41:80/ch5_0.264"
# cam7 = "rtsp://192.168.1.41:80/ch6_0.264"
# cam8 = "rtsp://192.168.1.41:80/ch7_0.264"
59 changes: 0 additions & 59 deletions ImageRecognition/send_frame.py

This file was deleted.

80 changes: 43 additions & 37 deletions ImageRecognition/src/ObjectDetectionYOLO.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@
model = YOLO("yolo-Wheights/yolov8n.pt")

url = "https://localhost:8080"
MSE_VALUE = 105.80
MSE_VALUE = 105.57

last_sent_image = []
frame_rate = 3


def post_request(camera_id: int, image):
global last_sent_image

# image = cv2.resize(image, (0.5, 0.5))

if last_sent_image[camera_id] is not None:
# Resizing
flat_last_sent_image = last_sent_image[camera_id].flatten()
Expand Down Expand Up @@ -69,51 +68,58 @@ def detection(camera_id: int, _: int):

print(f"capturing {camera_id}")

# FIXME camera capture takes to much time to load the camera connection (first time)
cap = cv2.VideoCapture(f"rtsp://192.168.1.41:80/ch{camera_id}_0.264")
cap.set(cv2.CAP_PROP_FPS, 5)
# cap = cv2.VideoCapture(f"rtsp://172.20.14.1:80/ch{camera_id}_0.264")

while True:
cap = cv2.VideoCapture(f"rtsp://192.168.1.41:80/ch{camera_id}_0.264")

prev_time = 0

# TODO handle status
status = "offline"

# TODO handle status
status = "offline"
print(f"started {camera_id}")

print(f"started {camera_id}")
while cap.isOpened():
success, img = cap.read()

while cap.isOpened():
success, img = cap.read()
time_elapsed = time.time() - prev_time

if not success:
print(f"No frame {camera_id}")
continue
if time_elapsed <= 1.0 / frame_rate:
continue

print(f"Captured frame from {camera_id}")
prev_time = time.time()

# cv2.imshow(f"Camera {camera_id}", img)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
if not success:
cap.release()
continue
print(f"Captured frame from {camera_id}")

status = "online"
results = model(img, stream=True, classes=0, conf=0.5, verbose=False)
foundPerson = False
# coordinates
for r in results:
boxes = r.boxes
for box in boxes:
# bounding box
x1, y1, x2, y2 = box.xyxy[0]
x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
cv2.rectangle(img, (x1, y1), (x2, y2), (255, 0, 255), 3)
# confidence
confidence = math.ceil((box.conf[0] * 100)) / 100
print("Confidence --->", confidence)
status = "online"
results = model(img, stream=True, classes=0, conf=0.5, verbose=False)
foundPerson = False
# coordinates
for r in results:
boxes = r.boxes
for box in boxes:
# bounding box
x1, y1, x2, y2 = box.xyxy[0]
x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)
cv2.rectangle(img, (x1, y1), (x2, y2), (255, 0, 255), 3)
# confidence
confidence = math.ceil((box.conf[0] * 100)) / 100
print(
f" Person detected in {camera_id} with Confidence ---> {confidence}"
)

foundPerson = True
foundPerson = True

if foundPerson:
_, image = cv2.imencode(".jpg", img)
if foundPerson:
_, image = cv2.imencode(".jpg", img)

post_request(camera_id, image)
post_request(camera_id, image)

cap.release()
cap.release()


def initBufferSize(size: int):
Expand Down
16 changes: 8 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ services:
env_file:
- .secrets.yml

openvidu:
image: openvidu/openvidu-dev:2.29.0
restart: on-failure # always
ports:
- "4443:4443"
env_file:
- ./Backend/.env-openvidu
# openvidu:
# image: openvidu/openvidu-dev:2.29.0
# restart: on-failure # always
# ports:
# - "4443:4443"
# env_file:
# - ./Backend/.env-openvidu

backend:
container_name: backend
image: node:21-alpine
depends_on:
- mongo
- openvidu
# - openvidu
restart: on-failure # always
ports:
- "8080:8080"
Expand Down
Loading