How to Convert Mat to ArrayList<Mat> Opencv Android

asked 2015-11-15 05:57:10 -0500

VeTaLio gravatar image

Hello everyone.I need to know,how to convert properly my Mat into ArrayList<mat>.
So at current moment i'm doing convert my Bitmap to mat,via bitmapToMat() method and after this,type of Mat equals to CvType.CV_8UC4.
So i want to use method Imgproc.calcHist(),where first parametr is ArrayList<mat>, and also,i know that i can convert Mat to ArrayList<mat> via method of converters:

    ArrayList<Mat> ListMat = new ArrayList<Mat>();
    Converters.Mat_to_vector_Mat(MySourceMat,ListMat);

and always i get this exception:

java.lang.IllegalArgumentException: CvType.CV_32SC2 != m.type() || m.cols()!=1 [MonoDroid] Mat [ 32641836CV_8UC1, isCont=true, isSubmat=false, nativeObj=0xffffffff9526cac0, dataAddr=0xffffffff81900010 ]

So what i tried:

Mat newMat = new Mat(MySourceMat.cols(),MySourceMat.rows(),CvType.CV_32SC2);
Converters.Mat_to_vector_Mat(newMat,ListMat);

And exception shows again,but this newMat have type CvType.CV_32SC2.
What can i do to resolve my problem? Thanks!!

edit retag flag offensive close merge delete

Comments

1
berak gravatar imageberak ( 2015-11-15 06:05:47 -0500 )edit

@berak thanks for the fast reply. I almost tried to this "example",but in my 2.4.11 version is no Method"asLists", it come only on 3.0.0 version ? thanks

VeTaLio gravatar imageVeTaLio ( 2015-11-15 06:14:24 -0500 )edit
berak gravatar imageberak ( 2015-11-15 06:21:11 -0500 )edit
1

maybe:

 ArrayList<Mat> ListMat = new ArrayList<Mat>();
 ListMat.add(image);
berak gravatar imageberak ( 2015-11-15 06:22:04 -0500 )edit

@berak lol, method add worked well. Thanks! But now i got another problems.
can you please help me translate to java this answer http://answers.opencv.org/question/75... THanks!

VeTaLio gravatar imageVeTaLio ( 2015-11-15 07:18:04 -0500 )edit

@berak i tried to do same thing as it showing on github example,but always getting this error ( on calcHist) : CvException [org.opencv.core.CvException: cv::Exception: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/histogram.cpp:1427: error: (-215) csz == 0 || csz == dims in function void cv::calcHist(cv::InputArrayOfArrays, const std::vector<int>&, cv::InputArray, cv::OutputArray, const std::vector<int>&, const std::vector<float>&, bool)

VeTaLio gravatar imageVeTaLio ( 2015-11-15 07:22:40 -0500 )edit

maybe start a new question (including some code) ?

berak gravatar imageberak ( 2015-11-15 07:38:16 -0500 )edit

@berak okay,i will do it now. You can also post your answer and i will mark as solution(List.Add(Mat)). Thanks!

VeTaLio gravatar imageVeTaLio ( 2015-11-15 07:41:23 -0500 )edit
VeTaLio gravatar imageVeTaLio ( 2015-11-15 08:07:36 -0500 )edit