Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crash in detrend function #2

Open
stephanschulz opened this issue Dec 3, 2020 · 1 comment
Open

crash in detrend function #2

stephanschulz opened this issue Dec 3, 2020 · 1 comment

Comments

@stephanschulz
Copy link

stephanschulz commented Dec 3, 2020

Thank you for also making this javascript version of your C++ code. It's awesome.

I ran your JS code successfully but am trying now to combine it with a handpose tracker in order to see if i can get a BPM from the palm of my hand.

I am using this opencv.js helper for my p5js project.
https://github.com/orgicus/p5.js-cv#installation

But the app crashes after running for a while at cv.split(a_signal, s); line.
Would you have any idea why that might be?
It's interesting that step variable in the console says "Exception: TypeError" when usually it is 2.

// Remove trend in a_signal
function detrend(a_signal, lambda) {
    let h = cv.Mat.zeros(a_signal.rows-2, a_signal.rows, cv.CV_32FC1);
    let i = cv.Mat.eye(a_signal.rows, a_signal.rows, cv.CV_32FC1);
    let t1 = cv.Mat.ones(a_signal.rows-2, 1, cv.CV_32FC1)
    let t2 = cv.matFromArray(a_signal.rows-2, 1, cv.CV_32FC1,
                             new Array(a_signal.rows-2).fill(-2));
    let t3 = new cv.Mat();
    t1.copyTo(h.diag(0)); t2.copyTo(h.diag(1)); t1.copyTo(h.diag(2));
    cv.gemm(h, h, lambda*lambda, t3, 0, h, cv.GEMM_1_T);
    cv.add(i, h, h, t3, -1);
    cv.invert(h, h, cv.DECOMP_LU);
    cv.subtract(i, h, h, t3, -1);
    let s = new cv.MatVector();
    console.log({a_signal});
    cv.split(a_signal, s); //crash here
     console.log({s});
    cv.gemm(h, s.get(0), 1, t3, 0, s.get(0), 0);
    cv.gemm(h, s.get(1), 1, t3, 0, s.get(1), 0);
    cv.gemm(h, s.get(2), 1, t3, 0, s.get(2), 0);
    cv.merge(s, a_signal);
    h.delete(); i.delete();
    t1.delete(); t2.delete(); t3.delete();
    s.delete();
}

Screen Shot 2020-12-03 at 11 37 26 AM

@AbhishekAnand-1
Copy link

[stephanschulz]
how can I run that program? on my computer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants