From 8f6ff8ea246e16eb9b94a5187bf366bbddd538ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Tainon?= Date: Wed, 16 Oct 2024 17:12:27 +0200 Subject: [PATCH] Add new OpenCV functions --- frontend/stepper/quickalgo_executor.ts | 4 +-- frontend/task/fixtures/test_opencv/index.ts | 2 +- frontend/task/libs/opencv/opencv_lib.tsx | 39 ++++++++++++++++++--- 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/frontend/stepper/quickalgo_executor.ts b/frontend/stepper/quickalgo_executor.ts index 0872d0d9..b7d44340 100644 --- a/frontend/stepper/quickalgo_executor.ts +++ b/frontend/stepper/quickalgo_executor.ts @@ -249,11 +249,11 @@ class QuickalgoExecutor { const libraryCallResult = await this.makeTimedLibraryCall(context, module, action, args); - const libraryCall: QuickalgoLibraryCall = { + const libraryCall: QuickalgoLibraryCall = JSON.parse(JSON.stringify({ module, action, args, - }; + })); await this.stepperContext.dispatch(stepperRecordLibraryCall(libraryCall, libraryCallResult)); diff --git a/frontend/task/fixtures/test_opencv/index.ts b/frontend/task/fixtures/test_opencv/index.ts index 2f4e998f..1865abbc 100644 --- a/frontend/task/fixtures/test_opencv/index.ts +++ b/frontend/task/fixtures/test_opencv/index.ts @@ -10,7 +10,7 @@ export default { includeBlocks: { groupByCategory: false, generatedBlocks: { - opencv: ["imread", "cvtColor", "imwrite"] + opencv: ["imread", "cvtColor", "flip", "rotate", "blur", "resize", "Canny", "imwrite"] }, standardBlocks: { includeAll: false, diff --git a/frontend/task/libs/opencv/opencv_lib.tsx b/frontend/task/libs/opencv/opencv_lib.tsx index fd7d0071..a54ae96b 100644 --- a/frontend/task/libs/opencv/opencv_lib.tsx +++ b/frontend/task/libs/opencv/opencv_lib.tsx @@ -5,6 +5,11 @@ const localLanguageStrings = { description: { imread: "imread(image) ouvre l'image", cvtColor: "cvtColor(image, couleur) convertit l'image dans la couleur fournie", + flip: "flip(image, flipCode) renverse l'image dans la direction choisie", + resize: "resize(image, newSize) redimensionne l'image", + blur: "blur(image, kernelSize) applique un flou sur l'image", + rotate: "rotate(image, rotateCode) fait pivoter l'image", + Canny: "Canny(image, threshold1, threshold2) détecte les contours sur une image", imwrite: "imwrite(fichier, image) enregistre l'image", }, }, @@ -22,22 +27,46 @@ export class OpenCvLib extends QuickAlgoLibrary { this.setLocalLanguageStrings(localLanguageStrings); - this.opencv = { - imread: this.generateRemoteHandler('opencv', 'imread'), - cvtColor: this.generateRemoteHandler('opencv', 'cvtColor'), - imwrite: this.generateRemoteHandler('opencv', 'imwrite'), - }; + const blocksList = [ + 'imread', + 'cvtColor', + 'flip', + 'resize', + 'blur', + 'rotate', + 'Canny', + 'imwrite', + ]; + + this.opencv = {}; + for (let block of blocksList) { + this.opencv[block] = this.generateRemoteHandler('opencv', block); + } this.customBlocks = { opencv: { opencv: [ { name: "imread", params: ["String"], yieldsValue: 'image'}, { name: "cvtColor", params: ["Image", "String"], yieldsValue: 'image'}, + { name: "flip", params: ["Image", "String"], yieldsValue: 'image'}, + { name: "resize", params: ["Image", null], yieldsValue: 'image'}, + { name: "blur", params: ["Image", null], yieldsValue: 'image'}, + { name: "rotate", params: ["Image", "String"], yieldsValue: 'image'}, + { name: "Canny", params: ["Image", "Number", "Number"], yieldsValue: 'image'}, { name: "imwrite", params: ["String", "Image"]}, ], } }; + this.customConstants = { + opencv: [ + {name: 'COLOR_BGR2GRAY', value: 6}, + {name: 'ROTATE_90_CLOCKWISE', value: 0}, + {name: 'ROTATE_180', value: 1}, + {name: 'ROTATE_90_COUNTERCLOCKWISE', value: 2}, + ], + }; + this.innerState = { }; }