Extract a 2d matrix from 4d matrix JS

Viewed 82

I'm using electron with openCV with opencv4nodejs. My goal is to do the Deep Learning based Human Pose Estimation using OpenCV tutorial in JS instead of Python.

I'm quite new to JS but I'm very familiar with Python and I know that if I want to extract a 2d array from a 4d array (like in stage 3.4 line 7 in the python code), I can do myArray[0, 0, :, :]. Is there a similar functionality in JS openCV build for matrix objects?

I have tried to use the at function of the matrix object but it returns the first element of the 2d submatrix, e.g. myArray.at(0,0) is equal to myArray.at(0,0,0,0). So it did not work.

If you know a solution with a normal JS array it's also good since I can convert between a matrix and array.

I could probably copy the submatrix element wise but it will be inefficient (and I don't know how to). If there is a function that could copy a matrix from a smaller dimension I would like to know. But the optimal solution would be to get a shallow copy of the submatrix.

Thanks in advance.

0 Answers
Related