Skip to content

Commit

Permalink
adicionado exemplo de detecção de bordas
Browse files Browse the repository at this point in the history
  • Loading branch information
Piemontez committed May 2, 2024
1 parent 5536b4f commit eec5218
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { edgeTabName } from './tabname';
* Sobel component and node
*/

export class CVSobelComponent extends CVFIOComponent {
export class SobelComponent extends CVFIOComponent {
static menu = { tabTitle: edgeTabName, title: 'Sobel' };

static processor = class SobelProcessor extends CVFNodeProcessor {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/opencv/edge/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './CVSobelComponent';
export * from './SobelComponent';
export * from './CannyComponent';
export * from './LaplacianComponent';
export * from './ScharrComponent';
Expand Down
98 changes: 98 additions & 0 deletions src/plugins/opencvTemplates/edge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import { CVVideoCaptureComponent } from '../opencv/inputs/CVVideoCaptureComponent';
import { CvtColorComponent } from '../opencv/conversors/CvtColorComponent';
import { CVFComponent } from '../../ide/components/NodeComponent';
import { useNodeStore } from '../../core/contexts/NodeStore';
import { ProjectTemplate } from '../../core/types/project-template';
import { makeXYPosition } from '../../core/utils/makeXYPosition';
import cv from 'opencv-ts';
import { EqualizeHistComponent } from '../opencv/others';
import { SobelComponent, CannyComponent, LaplacianComponent } from '../opencv/edge';
import { GaussianBlurComponent } from '../opencv/smoothing';

const group = 'OpenCV';

const EdgeSamplesAction: ProjectTemplate = {
group,
title: 'Edges Samples',
action: () => {
let comp: typeof CVFComponent | null;
let pos;

// Add Video
comp = useNodeStore.getState().getNodeType(CVVideoCaptureComponent.name);
pos = makeXYPosition(-3, 0);
const videoId = useNodeStore.getState().addNodeFromComponent(comp!, pos).id;

// Add Convert
comp = useNodeStore.getState().getNodeType(CvtColorComponent.name);
pos = makeXYPosition(-1, -1);
const cvtColorId = useNodeStore.getState().addNodeFromComponent(comp!, pos, { code: cv.COLOR_BGR2GRAY }).id;
// Add Convert
comp = useNodeStore.getState().getNodeType(GaussianBlurComponent.name);
pos = makeXYPosition(-1, 0);
const gaussianBlurId = useNodeStore.getState().addNodeFromComponent(comp!, pos, { code: cv.COLOR_BGR2GRAY }).id;
// Add Equalize
comp = useNodeStore.getState().getNodeType(EqualizeHistComponent.name);
pos = makeXYPosition(-1, 1);
const eqId = useNodeStore.getState().addNodeFromComponent(comp!, pos, { dsize: new cv.Size(128, 128) }).id;

// Add SobelComponent
comp = useNodeStore.getState().getNodeType(SobelComponent.name);
pos = makeXYPosition(1, -2);
const sobel01Id = useNodeStore.getState().addNodeFromComponent(comp!, pos).id;
// Add SobelComponent
comp = useNodeStore.getState().getNodeType(SobelComponent.name);
pos = makeXYPosition(2, -2);
const sobel02Id = useNodeStore.getState().addNodeFromComponent(comp!, pos).id;
// Add SobelComponent
comp = useNodeStore.getState().getNodeType(SobelComponent.name);
pos = makeXYPosition(3, -2);
const sobel03Id = useNodeStore.getState().addNodeFromComponent(comp!, pos).id;

// Add HistogramCalcComponent
comp = useNodeStore.getState().getNodeType(CannyComponent.name);
pos = makeXYPosition(1, 0);
const canny01Id = useNodeStore.getState().addNodeFromComponent(comp!, pos).id;
// Add HistogramCalcComponent
comp = useNodeStore.getState().getNodeType(CannyComponent.name);
pos = makeXYPosition(2, 0);
const canny02Id = useNodeStore.getState().addNodeFromComponent(comp!, pos).id;
// Add HistogramCalcComponent
comp = useNodeStore.getState().getNodeType(CannyComponent.name);
pos = makeXYPosition(3, 0);
const canny03Id = useNodeStore.getState().addNodeFromComponent(comp!, pos).id;

// Add HistogramCalcComponent
comp = useNodeStore.getState().getNodeType(LaplacianComponent.name);
pos = makeXYPosition(1, 2);
const laplacian01Id = useNodeStore.getState().addNodeFromComponent(comp!, pos).id;
// Add HistogramCalcComponent
comp = useNodeStore.getState().getNodeType(LaplacianComponent.name);
pos = makeXYPosition(2, 2);
const laplacian02Id = useNodeStore.getState().addNodeFromComponent(comp!, pos).id;
// Add HistogramCalcComponent
comp = useNodeStore.getState().getNodeType(LaplacianComponent.name);
pos = makeXYPosition(3, 2);
const laplacian03Id = useNodeStore.getState().addNodeFromComponent(comp!, pos).id;

useNodeStore.getState().addEdge(videoId, cvtColorId, 'out', 'src1');
useNodeStore.getState().addEdge(cvtColorId, gaussianBlurId, 'out', 'src1');
useNodeStore.getState().addEdge(cvtColorId, eqId, 'out', 'src1');

useNodeStore.getState().addEdge(cvtColorId, sobel01Id, 'out', 'src1');
useNodeStore.getState().addEdge(gaussianBlurId, sobel02Id, 'out', 'src1');
useNodeStore.getState().addEdge(eqId, sobel03Id, 'out', 'src1');

useNodeStore.getState().addEdge(cvtColorId, canny01Id, 'out', 'src1');
useNodeStore.getState().addEdge(gaussianBlurId, canny02Id, 'out', 'src1');
useNodeStore.getState().addEdge(eqId, canny03Id, 'out', 'src1');

useNodeStore.getState().addEdge(cvtColorId, laplacian01Id, 'out', 'src1');
useNodeStore.getState().addEdge(gaussianBlurId, laplacian02Id, 'out', 'src1');
useNodeStore.getState().addEdge(eqId, laplacian03Id, 'out', 'src1');

setTimeout(useNodeStore.getState().fitView, 100);
},
};

export default EdgeSamplesAction;
2 changes: 0 additions & 2 deletions src/plugins/opencvTemplates/histogram-cal.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { CVVideoCaptureComponent } from '../opencv/inputs/CVVideoCaptureComponent';
import { CvtColorComponent } from '../opencv/conversors/CvtColorComponent';
import { CVFComponent } from '../../ide/components/NodeComponent';
import { ThresholdComponent } from '../opencv/segmentation/ThresholdComponent';
import { useNodeStore } from '../../core/contexts/NodeStore';
import { ProjectTemplate } from '../../core/types/project-template';
import { CVResizeComponent } from '../opencv/geometricTransformations';
import { makeXYPosition } from '../../core/utils/makeXYPosition';
import cv from 'opencv-ts';
import { EqualizeHistComponent } from '../opencv/others';
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/opencvTemplates/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { PluginType } from '../../core/types/plugin';
import ThresholdSamplesAction from './threshold-samples';
import MorphologySamplesAction from './morphology-samples';
import HistogramCalcSamplesAction from './histogram-cal';
import EdgeSamplesAction from './edge';

const OpenCVTemplatesPlugin: PluginType = {
name: 'OpenCV Templates Plugin',
components: [],
templates: [
//
EdgeSamplesAction,
ThresholdSamplesAction,
MorphologySamplesAction,
HistogramCalcSamplesAction,
Expand Down

0 comments on commit eec5218

Please sign in to comment.