1

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?

2 Answers 2

1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

But it will give byte array which i don’t want because byte contains negative values but I need all positive values that’s why I’m tried with integer
0
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[] 

1 Comment

Please don't post only code as an answer, but also provide an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually of higher quality, and are more likely to attract upvotes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.