Dr-Swopt пре 1 недеља
родитељ
комит
46cf5e9388

+ 1 - 0
src/main.ts

@@ -3,6 +3,7 @@ import { AppModule } from './app.module';
 
 async function bootstrap() {
   const app = await NestFactory.create(AppModule);
+  app.enableCors(); // Allow requests from frontend
   await app.listen(process.env.PORT ?? 3000);
 }
 bootstrap();

+ 1 - 0
src/palm-oil/interfaces/palm-analysis.interface.ts

@@ -24,6 +24,7 @@ export interface AnalysisResponse {
   total_count: number;
   industrial_summary: IndustrialSummary;
   detections: DetectionResult[];
+  image_data?: string;
   inference_ms: number;
   processing_ms: number;
   archive_id: string;

+ 1 - 0
src/palm-oil/palm-oil.controller.ts

@@ -15,6 +15,7 @@ export class PalmOilController {
     }
     let res = await this.palmOilService.analyzeImage(file.buffer, file.originalname)
     // console.log(res)
+    // console.log(res.detections)
     return res;
   }
 

+ 6 - 5
src/palm-oil/palm-oil.service.ts

@@ -14,7 +14,7 @@ export class PalmOilService {
     private readonly scanner: ScannerProvider,
     @InjectRepository(History)
     private readonly historyRepository: Repository<History>,
-  ) {}
+  ) { }
 
   async analyzeImage(imageBuffer: Buffer, originalFilename: string = 'unknown.jpg'): Promise<AnalysisResponse> {
     const processingStart = performance.now();
@@ -52,7 +52,7 @@ export class PalmOilService {
       industrialSummary[det.class] = (industrialSummary[det.class] || 0) + 1;
     });
 
-    console.log('📊 Industrial Summary:', industrialSummary);
+    // console.log('📊 Industrial Summary:', industrialSummary);
 
     const processingMs = performance.now() - processingStart;
     const archiveId = `palm_${Date.now()}_${Math.floor(Math.random() * 1000)}`;
@@ -63,13 +63,13 @@ export class PalmOilService {
     history.filename = originalFilename;
     history.total_count = detections.length;
     history.industrial_summary = industrialSummary;
-    
+
     // Ensure detections is an array of objects, not a leaked JSON string
     history.detections = Array.isArray(detections) ? detections : [];
-    
+
     history.inference_ms = parseFloat(inferenceMs.toFixed(2));
     history.processing_ms = parseFloat(processingMs.toFixed(2));
-    
+
     await this.historyRepository.save(history);
 
     return {
@@ -78,6 +78,7 @@ export class PalmOilService {
       total_count: detections.length,
       industrial_summary: industrialSummary,
       detections: history.detections,
+      image_data: `data:image/jpeg;base64,${imageBuffer.toString('base64')}`, // Pass the image back
       inference_ms: history.inference_ms,
       processing_ms: history.processing_ms,
       archive_id: archiveId,

+ 5 - 5
src/palm-oil/providers/scanner.provider.ts

@@ -94,12 +94,12 @@ export class ScannerProvider implements OnModuleInit {
           class: className,
           confidence: parseFloat(confidence.toFixed(4)),
           is_health_alert: HEALTH_ALERT_CLASSES.includes(className),
-          // Normalize by dividing by 640 (the model input size)
+          // HEAVY LIFTING: Multiply ratio (0.0-1.0) by original pixels
           box: [
-            x1 / 640, 
-            y1 / 640, 
-            x2 / 640, 
-            y2 / 640
+            data[offset] * originalWidth,      // x1
+            data[offset + 1] * originalHeight, // y1
+            data[offset + 2] * originalWidth,  // x2
+            data[offset + 3] * originalHeight  // y2
           ], 
         });
       }