Issue in Mat type in Android+OpenCV

asked 2015-07-09 01:33:50 -0600

VPallavi gravatar image

double[] labels = {0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}; Mat labelsMat = new Mat(10,1, CvType.CV_32FC1); labelsMat.put(10, 1, labels); Log.d("Value of labels Mat is:: ",""+labelsMat.get(10, 1));

It's printing Null for labelsMat. Can anyone please tell me where i'm doing wrong?

edit retag flag offensive close merge delete

Comments

oh, dear, - indexing in c++/java goes from 0 to size-1, so labelsMat.get(9, 0) is the last valid item

berak gravatar imageberak ( 2015-07-09 01:42:40 -0600 )edit

Still it's printing null.

VPallavi gravatar imageVPallavi ( 2015-07-09 02:19:32 -0600 )edit
1

also you can't put(10,1,labels) do you see it now ? try:

double[] labels = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0}; 

Mat labelsMat = new Mat(10, 1, CvType.CV_32FC1); 
labelsMat.put(0, 0, labels); // put to the begin of the mat
Log.d("Value of labels Mat is " + labelsMat.get(9, 0)[0]); // get() returns an array

(hmm, maybe it's a good idea, to take a break from this, get a book on java basics, try the first 20 project-euler problems, or such ?)

berak gravatar imageberak ( 2015-07-09 02:30:10 -0600 )edit

Thank you for your answer as well as suggestion.

VPallavi gravatar imageVPallavi ( 2015-07-09 02:41:05 -0600 )edit