Ask Your Question

How to convet mat to a double array in java????

asked 2016-12-22 23:04:02 -0500

Neel Gohel gravatar image

updated 2016-12-23 00:54:45 -0500

berak gravatar image
Mat im= Imgcodecs.imread(d);
Mat inp=new Mat();
Mat newinp=new Mat();
inp.convertTo(newinp, CvType.CV_64F);
java.util.List<Mat> rgb=null;
Core.split(newinp, rgb);
Mat r1=rgb.get(0);
Mat g1=rgb.get(1);
Mat b1=rgb.get(2);
double[] r = null;
double[] b=null;
double[] g=null;

Now I want to convert Mat r1 to double[] r, Mat g1 to double[] g and Mat b1 to double[] b. What should I do???????

edit retag flag offensive close merge delete


may i ask, why you want to do this ? (also, why double[] ?)

berak gravatar imageberak ( 2016-12-23 00:57:08 -0500 )edit

I have a piece of code in Matlab, I am converting it to java.

Neel Gohel gravatar imageNeel Gohel ( 2016-12-23 01:06:12 -0500 )edit

opencv != matlab.

don't do that "line-by-line". tell us, what you're trying to achieve (on a higher level), then we can help you.

berak gravatar imageberak ( 2016-12-23 01:09:57 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-12-23 01:04:38 -0500

pi-null-mezon gravatar image

You should check if r1 continuous (call r1.isContinuous()). Ad if it is, then get pointer to the beginning of the data: r = r1.ptr<double>(0), same for the g1 and b1.

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-12-22 23:04:02 -0500

Seen: 1,424 times

Last updated: Dec 23 '16