Skip to content

Commit

Permalink
Add new OpenCV functions
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienTainon committed Oct 16, 2024
1 parent 31616ca commit 8f6ff8e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
4 changes: 2 additions & 2 deletions frontend/stepper/quickalgo_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
2 changes: 1 addition & 1 deletion frontend/task/fixtures/test_opencv/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
39 changes: 34 additions & 5 deletions frontend/task/libs/opencv/opencv_lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
Expand All @@ -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 = {
};
}
Expand Down

0 comments on commit 8f6ff8e

Please sign in to comment.