Im trying to detect circle only at real-time webcam, and draw circle on it.

asked 2019-06-06 02:05:45 -0500

Adam108 gravatar image

updated 2019-06-06 02:50:46 -0500

Hi. I trying to detect circle only on real-time webcam video and trying to draw circle border on my targeted circle, but right now I can draw a circle on output on a random target, please help me to get the circle target. I'm developing this work in javascript and using opencv.js. That random detection also detecting on video bottom only not in any other places.

   function processVideo() {
    try {
        if (!streaming) {
            // clean and stop.
            src.delete();
            dst.delete();
            dstC1.delete();
            dstC3.delete();

            return;
        }

        let begin = Date.now();
        // start processing.
        cap.read(src);
        cv.cvtColor(src, dst, cv.COLOR_RGBA2GRAY);
        cv.blur(dst, dstC1, ksize, anchor, cv.BORDER_DEFAULT); // blur the image to avoids noise 
        cv.Canny(dstC1, dstC1, 50, 100, 3, false); // black and white border 

        let contours = new cv.MatVector();
        let hierarchy = new cv.Mat();

        cv.findContours(dstC1, contours, hierarchy, cv.RETR_CCOMP, cv.CHAIN_APPROX_SIMPLE, offset = new cv.Point(0, 0));

        let cnt = contours.get(0);

        let contoursColor = new cv.Scalar(255, 255, 255);
        let circleColor = new cv.Scalar(255, 0, 0);
        let circle = cv.minEnclosingCircle(cnt);// this one for circle
        cv.drawContours(dstC1, contours, 0, contoursColor, 1, 8, hierarchy, 100);
        for (let i = 0; i < 4; i++) {
            cv.circle(dstC1, circle.center, circle.radius, circleColor, 3);

        }
        cv.imshow('canvasOutput', dstC1);

        let delay = 1000/FPS - (Date.now() - begin);
        setTimeout(processVideo, delay);
    } catch (err) {
        utils.printError(err);
    }
};

please help me to detect circle only. Thank you.

edit retag flag offensive close merge delete

Comments

Anyone can help me with this?

Adam108 gravatar imageAdam108 ( 2019-06-10 03:14:37 -0500 )edit