Browse Source

udpate facial rec

Dr-Swopt 1 week ago
parent
commit
f7f5fe7488

+ 4 - 3
src/face/face.controller.ts

@@ -3,12 +3,13 @@ import { FaceService } from './face.service';
 
 @Controller('face')
 export class FaceController {
-  constructor(private readonly faceService: FaceService) { }
+  constructor(private readonly faceService: FaceService) {}
 
   @Post('scan')
-  async scan(@Body() body: { imageBase64: string }) {
+  async scan(@Body() body: { imageBase64: string; modelName?: string }) {
     const buffer = Buffer.from(body.imageBase64, 'base64');
-    return this.faceService.recognizeFace(buffer);
+    // Pass optional modelName to service
+    return this.faceService.recognizeFace(buffer, body.modelName);
   }
 
   @Post('enroll')

+ 7 - 0
src/face/face.module.ts

@@ -15,6 +15,13 @@ import { FaceController } from './face.controller';
           package: 'facerecognition',  // must match `package` in proto
           protoPath: join(__dirname, 'proto/face_recognition.proto'),
           url: 'localhost:50051',       // your Python gRPC server
+          loader: {
+            keepCase: true,   // <--- critical: preserve model_name as snake_case
+            longs: String,
+            enums: String,
+            defaults: true,
+            oneofs: true,
+          },
         },
       },
     ]),

+ 4 - 4
src/face/face.service.ts

@@ -19,8 +19,10 @@ export class FaceService implements OnModuleInit {
     this.faceGrpc = this.client.getService<any>('FaceRecognitionService');
   }
 
-  async recognizeFace(imageBuffer: Buffer) {
-    const res = await this.faceGrpc.Recognize({ image: imageBuffer }).toPromise();
+  async recognizeFace(imageBuffer: Buffer, modelName?: string) {
+    let payload = { image: imageBuffer, model_name: modelName as string }
+    // console.log(payload)
+    const res = await this.faceGrpc.Recognize(payload).toPromise();
 
     let photoBase64: string | null = null;
     if (res.image && res.image.length > 0) {
@@ -39,10 +41,8 @@ export class FaceService implements OnModuleInit {
   }
 
   async getAllEmployees(): Promise<Employee[]> {
-    // Get names + images from gRPC
     const res = await this.faceGrpc.GetAllEmployees({}).toPromise();
 
-    // Map each employee to include base64 photo URL
     return res.employees.map((emp: { name: string; image: Buffer }) => {
       let photoUrl: string | null = null;
       if (emp.image && emp.image.length > 0) {

+ 5 - 8
src/face/proto/face_recognition.proto

@@ -5,16 +5,17 @@ package facerecognition;
 // The request message containing the image bytes
 message FaceRequest {
   bytes image = 1;
+  string model_name = 2; // optional: "VGG-Face", "FaceNet", "OpenFace"
 }
 
-// The response message containing recognition results, now includes image
+// The response message containing recognition results
 message FaceResponse {
   string name = 1;
   float confidence = 2;
-  bytes image = 3; // newly added: return matched employee image
+  bytes image = 3; // matched employee image
 }
 
-// New messages for enrollment
+// Enrollment messages
 message EnrollFaceRequest {
   bytes image = 1;
   string name = 2;
@@ -28,7 +29,7 @@ message EnrollFaceResponse {
 // Messages for getting all employees
 message Employee {
   string name = 1;
-  bytes image = 2; // enrolled photo
+  bytes image = 2;
 }
 
 message EmployeeListRequest {}
@@ -51,10 +52,6 @@ message DeleteEmployeeResponse {
 service FaceRecognitionService {
   rpc Recognize(FaceRequest) returns (FaceResponse);
   rpc EnrollFace(EnrollFaceRequest) returns (EnrollFaceResponse);
-
-  // Updated RPC to return employee name + photo
   rpc GetAllEmployees(EmployeeListRequest) returns (EmployeeListResponse);
-
-  // Fixed to match the message name
   rpc DeleteEmployee(DeleteRequest) returns (DeleteEmployeeResponse);
 }

+ 2 - 1
tsconfig.build.json

@@ -2,7 +2,8 @@
   "extends": "./tsconfig.json",
   "compilerOptions": {
     "outDir": "./dist",
-    "rootDir": "./src"
+    "rootDir": "./src",
+    "incremental": false
   },
   "include": [
     "src/**/*.ts",