-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to finding contours in image #49
Comments
Hi, thanks for the issue! The example with the code you are able to find on CodePen: https://codepen.io/WorldThirteen/pen/wONzjL |
Is there a similar pointPolygonTest function?
|
No, we have no such function yet and have no plans to implement it in the nearest future. But we are open for the contribution. |
Thanks; We use the function: cv.pointPolygonTest (contour, pt, measureDist) Mainly this |
Thank you guys for interest and feedback. Currently GammaCV support only edges detection and hasn't support algorithms for contour segmentation, but we have a plans to add it in future. If you would like to help with it welcome to contribute. |
@crapthings dependent on case you have, if you looking for a contour of squared area you can detect edges then using Hough transform extract lines and then using heuristic approach try to find object contour you interested in |
The documentation on pcLines is not very complete. There's no example that tell the name of the function for example. Is it |
Happy to take a PR. A PClines example is provided. |
Thank you @WorldThirteen . As you can see from my other issue I already found the example code :) |
Can you please post the working example for pclines here? |
Sorry if the question sounds very naive as I am very new to js. But how do we pass the input to each of these function and run them? |
Thanks for the quick reply @rmhrisk. I have tried to integrate the sample code with that mentioned in the get started. Here is the code:
|
You have a line const context = { line: new gm.Line() }; I mean: var params = newFunction()
function newFunction() {
return {
PROCESSING: {
name: 'PROCESSING',
dCoef: {
name: 'Downsample',
type: 'constant',
min: 1,
max: 4,
step: 1,
default: 2,
},
},
PCLINES: {
name: 'PC LINES',
count: {
name: 'Lines Count',
type: 'uniform',
min: 1,
max: 100,
step: 1,
default: 10,
},
layers: {
name: 'Layers Count',
type: 'constant',
min: 1,
max: 5,
step: 1,
default: 2,
},
},
};
};
const width = 500;
const heigth = 400;
// initialize WebRTC stream and session for runing operations on GPU
const stream = new gm.CaptureVideo(width, heigth);
const sess = new gm.Session();
const canvasProcessed = gm.canvasCreate(width, heigth);
// session uses a context for optimize calculations and prevent recalculations
// context actually a number which help algorythm to run operation efficiently
let context = 0;
// allocate memeory for storing a frame and calculations output
const input = new gm.Tensor('uint8', [heigth, width, 4]);
const context = { line: new gm.Line(); };
// construct operation grap which is actially a Canny Edge Detector
let pipeline = gm.grayscale(input);
pipeline = gm.downsample(pipeline, 2, 'max');
pipeline = gm.gaussianBlur(pipeline, 3, 1);
pipeline = gm.dilate(pipeline, [3, 3]);
pipeline = gm.sobelOperator(pipeline);
pipeline = gm.cannyEdges(pipeline, 0.25, 0.75);
pipeline = gm.pcLinesTransform(pipeline, 3, 2, 2);
// initialize graph
sess.init(pipeline);
// allocate output
const output = gm.tensorFrom(pipeline);
// create loop
const tick = () => {
requestAnimationFrame(tick);
// Read current in to the tensor
stream.getImageBuffer(input);
//
const maxP = Math.max(input.shape[0], input.shape[1]);
let lines = [];
// session.runOp(operation, frame, output);
sess.runOp(pipeline, context, output);
gm.canvasFromTensor(canvasProcessed, input);
for (let i = 0; i < output.size / 4; i += 1) {
const y = ~~(i / output.shape[1]);
const x = i - (y * output.shape[1]);
const value = output.get(y, x, 0);
const x0 = output.get(y, x, 1);
const y0 = output.get(y, x, 2);
if (value > 0.0) {
lines.push([value, x0, y0]);
}
}
lines = lines.sort((b, a) => a[0] - b[0]);
console.log(lines.length)
lines = lines.slice(0, 10);
// console.log(lines)
for (let i = 0; i < lines.length; i += 1) {
context.line.fromParallelCoords(
lines[i][1] * params.PROCESSING.dCoef, lines[i][2] * params.PROCESSING.dCoef,
input.shape[1], input.shape[0], maxP, maxP / 2,
);
gm.canvasDrawLine(canvasProcessed, context.line, 'rgba(0, 255, 0, 1.0)');
}
context += 1;
}
function main() {
// start capturing a camera and run loop
stream.start();
tick();
document.body.children[0].appendChild(canvasProcessed);
}
main() Note: I haven't checked if this code has other errors. |
rt
The text was updated successfully, but these errors were encountered: