Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

in opencv.js function cv.findTransformECC what is inputMask?

[findTransformECC] (https://docs.opencv.org/master/dc/d6b/group__video__track.html#ga1aa357007eaec11e9ed03500ecbcbe47) has 2 optional parameter (inputMask and gaussFiltSize) but if you don't include them you get an error.

so what should be used for inputMask? "null" does not work.

function Align_img(){

    let image_baseline = cv.imread(imgElement_Baseline);
    let image = cv.imread('imageChangeup');

    let im1_gray = new cv.Mat();
    let im2_gray = new cv.Mat();
    let im2_aligned = new cv.Mat();

    //get size of baseline image
    var width1 = image_baseline.cols;
    var height1 = image_baseline.rows;

    //resize image to baseline image
    let dim1 = new cv.Size(width1, height1);
    cv.resize(image, image, dim1, cv.INTER_AREA);

    // Convert images to grayscale
    cv.cvtColor(image_baseline, im1_gray, cv.COLOR_BGR2GRAY);
    cv.cvtColor(image, im2_gray, cv.COLOR_BGR2GRAY);

    // Find size of image1
    let dsize = new cv.Size(image_baseline.rows, image_baseline.cols);

    // Define the motion model
    const warp_mode = cv.MOTION_HOMOGRAPHY;

    // Define 3x3 matrix and initialize the matrix to identity
    let warp_matrix = cv.Mat.eye(3, 3, cv.CV_8U);

    // Specify the number of iterations.
    const number_of_iterations = 5000;

    // Specify the threshold of the increment in the correlation coefficient between two iterations
    const termination_eps = 0.0000000001; //1e-10;

    // Define termination criteria
    //const criteria = (cv.TERM_CRITERIA_EP | cv.TERM_CRITERIA_COUNT, number_of_iterations,  termination_eps);
    let criteria = new cv.TermCriteria(cv.TERM_CRITERIA_EP | cv.TERM_CRITERIA_COUNT, number_of_iterations,  termination_eps);

    //Run the ECC algorithm. The results are stored in warp_matrix.
    //let inputMask = new cv.Mat.zeros(im1_gray.size(), cv.CV_8UC3); //uint8
    cv.findTransformECC(im1_gray, im2_gray, warp_matrix, warp_mode, criteria, null, 5);

    // Use warpPerspective for Homography
    cv.warpPerspective (image, im2_aligned, warp_matrix, dsize, cv.INTER_LINEAR + cv.WARP_INVERSE_MAP);

    cv.imshow('imageChangeup', im2_aligned);

    im1_gray.delete();
    im2_gray.delete();
    im2_aligned.delete();

};

in opencv.js function cv.findTransformECC what is inputMask?

How do you represent "inputMask=None" 6th argument in Javascript? "null" does not work. The argument IS NOT optional as it outlines in docs.

[findTransformECC] (https://docs.opencv.org/master/dc/d6b/group__video__track.html#ga1aa357007eaec11e9ed03500ecbcbe47) has 2 optional parameter (inputMask and gaussFiltSize) but if you don't include them you get an error.

so what should be used for inputMask? "null" does not work.

function Align_img(){

    let image_baseline = cv.imread(imgElement_Baseline);
    let image = cv.imread('imageChangeup');

    let im1_gray = new cv.Mat();
    let im2_gray = new cv.Mat();
    let im2_aligned = new cv.Mat();

    //get size of baseline image
    var width1 = image_baseline.cols;
    var height1 = image_baseline.rows;

    //resize image to baseline image
    let dim1 = new cv.Size(width1, height1);
    cv.resize(image, image, dim1, cv.INTER_AREA);

    // Convert images to grayscale
    cv.cvtColor(image_baseline, im1_gray, cv.COLOR_BGR2GRAY);
    cv.cvtColor(image, im2_gray, cv.COLOR_BGR2GRAY);

    // Find size of image1
    let dsize = new cv.Size(image_baseline.rows, image_baseline.cols);

    // Define the motion model
    const warp_mode = cv.MOTION_HOMOGRAPHY;

    // Define 3x3 matrix and initialize the matrix to identity
    let warp_matrix = cv.Mat.eye(3, 3, cv.CV_8U);

    // Specify the number of iterations.
    const number_of_iterations = 5000;

    // Specify the threshold of the increment in the correlation coefficient between two iterations
    const termination_eps = 0.0000000001; //1e-10;

    // Define termination criteria
    //const criteria = (cv.TERM_CRITERIA_EP | cv.TERM_CRITERIA_COUNT, number_of_iterations,  termination_eps);
    let criteria = new cv.TermCriteria(cv.TERM_CRITERIA_EP | cv.TERM_CRITERIA_COUNT, number_of_iterations,  termination_eps);

    //Run the ECC algorithm. The results are stored in warp_matrix.
    //let inputMask = new cv.Mat.zeros(im1_gray.size(), cv.CV_8UC3); //uint8
    cv.findTransformECC(im1_gray, im2_gray, warp_matrix, warp_mode, criteria, null, 5);

    // Use warpPerspective for Homography
    cv.warpPerspective (image, im2_aligned, warp_matrix, dsize, cv.INTER_LINEAR + cv.WARP_INVERSE_MAP);

    cv.imshow('imageChangeup', im2_aligned);

    im1_gray.delete();
    im2_gray.delete();
    im2_aligned.delete();

};