codeboost / opencv-node

Use OpenCV with node.js
54 stars 9 forks source link

Populate a matrix manually #15

Open claudebossy opened 10 years ago

claudebossy commented 10 years ago

Hello,

I've tried to populate a matrix myself, for example have a matrix 3x3: 1 3 5 2 4 6 7 8 9

But I couldn't find a way to do it, in C++ we can use mat.at(0,0) = 1 for example, to change a value in the matrix. Is it already possible to do it and I'm missing something or is it something not implemented? Ideally doing something like: var mat = new cv.Mat(3, 3, type, [1,3,5,2,4,6,7,8,9]) or mat.at(i,j,value)

Also my goal was then to use cv::calibrateCamera, cv::solvePnP and cv::Rodrigues which are not implemented yet. So once I understand how to populate a matrix I can try to implement myself those new functions unless you can do it fast (I've already spent 1 and a half days trying to do it unsuccessfully...)

Thanks in advance.

codeboost commented 10 years ago

Mat::at() should work in Javascript as well. Are you getting an error ?

I have not worked on this in a long time and I cannot dedicate much time to it now, as there hasn't been too much interest in the project from the public at large.

But I can try and guide you on how to implement more extensions - it's fairly easy. I have used a generator to generate most of the functions, but I think it's ok to just implement them manually from now on, as there's not so much work to do.

To implement the constructor you want, check out opencvjs.cpp and look at how other constructors for cv.Mat work (JMat::__constructor methods), then you can write your own in a similar fashion.

claudebossy commented 10 years ago

Yes I'm getting an error, I've tried for example: var mat = new cv.Mat(3,3,cv.CV_64FC3); mat.at(0,0) = 1;

And I get: ReferenceError: Invalid left-hand side in assignment

I think I can manage to add new functions, at least I could try if I manage to at least populate a simple 3x3 matrix first =)