Converting python code to javascript code.

asked 2019-06-04 05:30:27 -0500

Adam108 gravatar image

updated 2019-06-04 05:44:19 -0500

I'm trying to convert python code to javascript code to detect an object in real life with webcam, I do have converted some lines but few lines are unable to find for javascript. please help me.

def find_marker(image):
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (5, 5), 0)
edged = cv2.Canny(gray, 35, 125)

cnts = cv2.findContours(edged.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

cnts = imutils.grab_contours(cnts) // fallowing three line i don't know how to convert to javascript.
c = max(cnts, key = cv2.contourArea)
return cv2.minAreaRect(c)

Following code is javascript which I tried to convert.

    function findMarker(src){

    cv.cvtColor(src, dst, cv.COLOR_RGBA2GRAY);
    let ksize = new cv.Size(3, 3);
    let anchor = new cv.Point(-1, -1);
    cv.blur(dst, dstC1, ksize, anchor, cv.BORDER_DEFAULT); 
    cv.Canny(dstC1, dstC1, 50, 100, 3, false); 
    let contours = new cv.MatVector();
    let hierarchy = new cv.Mat();
    cv.findContours(dstC1, contours, hierarchy, cv.RETR_CCOMP, cv.CHAIN_APPROX_SIMPLE);        

    src.delete();
    dst.delete();
    dstC1.delete();

}

I try to track a piece of paper in real time webcam video, so now trying to find my marker.

edit retag flag offensive close merge delete