vishal s.
vishal s.

Reputation: 380

how to get Integer array from mat object and viceversa

I have tried with this 1 code but I am not sure if am right

this is the code which I have tried :

Mat originalImage = Highgui.imread(path);
int[] imageInByte = new int[(int) (originalImage.total() * originalImage.channels())];

also I want to know how to get mat from integer array?

Upvotes: 1

Views: 345

Answers (2)

city945
city945

Reputation: 16

Mat mRgb = Imgcodecs.imread("test.jpg");
MatOfInt iRgb = new MatOfInt(CvType.CV_32S);// middle type
mRgb.convertTo(iRgb, CvType.CV_32S);// 复制mRgb的数据到 iRgb
int[] dataArray = new int[(int)(iRgb.total()*iRgb.channels())];
iRgb.get(0,0, dataArray);// iRgb数据 int[] 

Upvotes: 0

fireant
fireant

Reputation: 14538

After allocating the array,

byte imageInByte[] = new byte[originalImage.total() * originalImage.channels()];

You can copy the array from C++/JNI,

originalImage.get(0, 0, imageInByte);

To update the array in C++/JNI

originalImage.put(0, 0, imageInByte);

Upvotes: 1

Related Questions