Ask Your Question
1

findHomography error with opencv.js "Uncaught BindingError"

asked 2020-08-31 21:08:58 -0600

bernard55 gravatar image

updated 2020-08-31 21:12:03 -0600

I'm attempting to reproduce Satya Mallick's great work from here but in JavaScript.

here is a screen shot of the debug match: https://imgur.com/8i4Gxlh

however on the findHomography() call I am getting an error:

Uncaught BindingError {name: "BindingError", message: "Cannot pass "[object Object],[object Object],[obje…Object],[object Object],[object Object]" as a Mat", stack: "BindingError: Cannot pass "[object Object],[object…t.onclick (http://localhost:8082/opencv#:190:194)"}message: "Cannot pass "[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]" as a Mat"name: "BindingError"stack: "BindingError: Cannot pass "[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]" as a Mat↵    at BindingError.<anonymous> (http://localhost:8082/js/opencv_4_3_0.js:30:7971681)↵    at new BindingError (eval at createNamedFunction (http://localhost:8082/js/opencv_4_3_0.js:30:7971390), <anonymous>:4:34)↵    at throwBindingError (http://localhost:8082/js/opencv_4_3_0.js:30:7976808)↵    at RegisteredPointer.nonConstNoSmartPtrRawPointerToWireType [as toWireType] (http://localhost:8082/js/opencv_4_3_0.js:30:7985609)↵    at Object.findHomography (eval at new_ (http://localhost:8082/js/opencv_4_3_0.js:30:7995155), <anonymous>:7:26)↵    at Object.proto.<computed> [as findHomography] (http://localhost:8082/js/opencv_4_3_0.js:30:7982013)↵    at Align_img2 (http://localhost:8082/opencv:1925:20)↵    at HTMLAnchorElement.onclick (http://localhost:8082/opencv#:190:194)"__proto__: Error
throwBindingError @ opencv_4_3_0.js:30
nonConstNoSmartPtrRawPointerToWireType @ opencv_4_3_0.js:30
findHomography @ VM404261:7
proto.<computed> @ opencv_4_3_0.js:30
Align_img2 @ opencv:1925
onclick @ VM406404 opencv:190

Here is the code:

function Align_img2() {

        //image_A is the original image we are trying to align to
        //image_B is the image we are trying to line up correctly

        let image_A = cv.imread(imgElement_Baseline);
        let image_B = cv.imread('imageChangeup');

        let image_A_gray = new cv.Mat();
        let image_B_gray = new cv.Mat();

        //get size of baseline image (image A)
        var image_A_width = image_A.cols;
        var image_A_height = image_A.rows;

        //resize image B to the baseline (image A) image
        let image_A_dimensions = new cv.Size(image_A_width, image_A_height);
        cv.resize(image_B, image_B, image_A_dimensions, cv.INTER_AREA);

        // Convert both images to grayscale
        cv.cvtColor(image_A, image_A_gray, cv.COLOR_BGRA2GRAY);
        cv.cvtColor(image_B, image_B_gray, cv.COLOR_BGRA2GRAY);

        // Initiate detector
        var orb = new cv.ORB(1000);
        var kpv_image_A = new cv.KeyPointVector();
        var kpv_image_B = new cv.KeyPointVector();
        var descriptors_image_A =new cv.Mat();
        var descriptors_image_B =new cv.Mat();
        var image_A_keypoints=new cv.Mat();
        var image_B_keypoints =new cv.Mat();

        mask = new cv.Mat();

        orb.detectAndCompute(image_A_gray, new cv.Mat(), kpv_image_A, descriptors_image_A);
        orb.detectAndCompute(image_B_gray ...
(more)
edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2020-09-03 09:57:33 -0600

kpachinger gravatar image
  1. findHomography expects srcPoints/dstPoints (points_A/points_B) to be new cv.Mat(3,3,cv.CV_32F)

    The input arrays should be 2D or 3D point sets in function 'findHomography'.

  2. warpPerspective(image_B_gray, dst, h, new cv.Size(rows,cols)) expects M (or h) to be a 3x3 transform matrix

    (M0.type() == CV_32F || M0.type() == CV_64F) && M0.rows == 3 && M0.cols == 3 in function 'warpPerspective'*

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-08-31 21:08:58 -0600

Seen: 1,413 times

Last updated: Sep 03 '20