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

important parallelization improvements and fixes #17

Merged
merged 6 commits into from
Jan 25, 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,9 @@ dist
# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
# VSCode files
.vscode-test
.vscode

# yarn v2
.yarn/cache
Expand Down
2 changes: 0 additions & 2 deletions Backend/.env-openvidu
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
OPENVIDU_SECRET=MY_SECRET
OPENVIDU_WEBHOOK=true
OPENVIDU_WEBHOOK_ENDPOINT=https://localhost:8080/media-server


Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class MachineLearningController {
new ParseFilePipeBuilder()
.addFileTypeValidator({ fileType: 'image/jpeg' })
.addMaxSizeValidator({
maxSize: 100000, // 100Kb
maxSize: 50000000, // 100Kb
})
.build({
errorHttpStatusCode: HttpStatus.UNPROCESSABLE_ENTITY,
Expand Down
1 change: 0 additions & 1 deletion Backend/src/cameraStream/cameraStream.gateway.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Test, TestingModule } from '@nestjs/testing';
import { CameraStreamGateway } from './cameraStream.gateway';
import { JwtModule } from '@nestjs/jwt';

import { OpenVidu } from 'openvidu-node-client';
import { CSSOpenVidu } from './open-vidu.service';
import { DatabaseService } from '../database/database.service';

Expand Down
2 changes: 1 addition & 1 deletion Backend/src/database/database.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('DatabaseService', () => {
});

it('should get aggregated data', async () => {
const aggregateData = await databaseService.aggregateCamera();
const aggregateData = await databaseService.aggregateCamera('all');

expect(aggregateData).not.toBeNull();
});
Expand Down
86 changes: 38 additions & 48 deletions Backend/src/database/database.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ export class DatabaseService {
);
}

async initDBNvr() {
const data = {
name: 'NVR',
};
const filter = {
name: 'NVR',
ip: process.env.NVR_IP_ADDRESS,
channels: [0, 1, 2, 3, 4, 5, 6, 7],
};

const size = await this.DB.collection('General').countDocuments(filter);

if (size == 0) {
await this.DB.collection('General').insertOne(data);
}
}

// If no camera exists it automatically creates one with the default config in camera.config.ts file
async initCameras() {
const size = await this.DB.collection('camera_names').countDocuments();
Expand All @@ -75,6 +92,7 @@ export class DatabaseService {

this.DB = client.db('csd');
this.initDBUser();
this.initDBNvr();
this.initCameras();
}

Expand Down Expand Up @@ -117,9 +135,23 @@ export class DatabaseService {
return this.DB.collection('camera_names').find().toArray();
}

aggregateCamera(filter?: FiltersAvailable): Promise<Document[]> {
aggregateCamera(filter: FiltersAvailable): Promise<Document[]> {
return this.DB.collection('cameras')
.aggregate()
.aggregate([
{
$addFields: {
intrusionDetection: {
$cond: {
if: {
$ifNull: ['$intrusionDetection', false],
},
then: true,
else: false,
},
},
},
},
])
.match(this.getFilter(filter))
.group({
_id: '$cameraId',
Expand Down Expand Up @@ -165,7 +197,7 @@ export class DatabaseService {
});
}

private getFilter(filter?: FiltersAvailable) {
private getFilter(filter: FiltersAvailable) {
switch (filter) {
case 'intrusionDetection':
return {
Expand Down Expand Up @@ -222,55 +254,13 @@ export class DatabaseService {
// TODO TESTME
// Returns NVR info such as IP address and available channels
async getNVRData(): Promise<Document> {
const array = await this.getOtherwiseInsert(
'General',
{
name: 'NVR',
},
{
name: 'NVR',
ip: process.env.NVR_IP_ADDRESS,
channels: cameraIds,
},
);
const array = await this.getRawDataArray('General', {
name: 'NVR',
});

return {
ip: process.env.NVR_IP_ADDRESS,
channels: array[0].channels,
};

// try {
// const array = await this.getRawDataArray('General', {
// name: 'NVR',
// });
// return array[0];
// } catch (e) {
// if (e instanceof NotFoundException) {
// const data = {
// name: 'NVR',
// ip: process.env.NVR_IP_ADDRESS,
// channels: [0, 1, 2, 3, 4, 5, 6, 7],
// };
//
// await this.DB.collection(`General`).insertOne(data);
// return data;
// } else {
// console.error(e);
// }
// }
}

async getOtherwiseInsert(
name: string,
filter: Filter<Document>,
data: Document,
): Promise<WithId<Document>[]> {
const size = await this.DB.collection(name).countDocuments(filter);

if (size == 0) {
await this.DB.collection(name).insertOne(data);
}

return await this.getRawDataArray(name, filter);
}
}
19 changes: 19 additions & 0 deletions ImageRecognition/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import concurrent.futures
from src.ObjectDetectionYOLO import detection

if __name__ == "__main__":
with concurrent.futures.ThreadPoolExecutor() as executor:
args: (int, int) = [(i, i) for i in range(0, 8)]

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


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"
5 changes: 3 additions & 2 deletions ImageRecognition/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
opencv-python~=4.8.1.78
numpy~=1.26.1
ping3~=4.0.4
python>=3.8
PyTorch>=1.8
ultralytics>=8.1.5
scikit-learn~=1.3.2
torch>=1.8
Loading
Loading