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

asked 2020-07-05 17:27:53 -0600

bernard55 gravatar image

updated 2020-07-08 11:53:32 -0600

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] ( 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);


edit retag flag offensive close merge delete


did you try

   cv.findTransformECC(im1_gray, im2_gray, warp_matrix, warp_mode, criteria);
sturkmen gravatar imagesturkmen ( 2020-07-05 18:41:50 -0600 )edit

yes, but you get an error about the API expecting 7 variables but only getting 5. There is a bit of discussion on the forum about this being an issue with Python with the latest version as well.

bernard55 gravatar imagebernard55 ( 2020-07-06 09:41:42 -0600 )edit

also, if i give it a mask i get an uncaught exception. I love opencv and the js version but error handling is not great.

bernard55 gravatar imagebernard55 ( 2020-07-06 09:44:17 -0600 )edit

Here is error:

opencv_4_3_0.js:30 Uncaught BindingError {name: "BindingError", message: "function findTransformECC called with 5 arguments, expected 7 args!", stack: "BindingError: function findTransformECC called wit…t.onclick (http://localhost:8082/opencv#:187:176)"} message: "function findTransformECC called with 5 arguments, expected 7 args!" name: "BindingError"

same issue with 3.4.0

bernard55 gravatar imagebernard55 ( 2020-07-06 09:59:53 -0600 )edit

here is the python comment

bernard55 gravatar imagebernard55 ( 2020-07-06 10:05:05 -0600 )edit