Ask Your Question
0

How can I store a char[] in Matrix Object in OpenCV Java?

asked 2016-01-14 16:15:40 -0600

ocv_user gravatar image

Hi, I have unsigned data stored in a char[]. The code is:

    Mat mat1=new Mat();
    mat1.create(640, 512, CvType.CV_16UC1);
    mat1.put(0, 0,chararr);

However, put() function does not support this conversion. Is there any other way I can do it? An answer would be appreciated. Thank you.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-01-14 16:31:37 -0600

Tetragramm gravatar image

One of the Mat constructors takes a pointer as an argument.

cv::Mat charMat(640,512,CV_16UC1,chararr);

Note that it does not copy the data, so you may need to do .clone() if your chararr is not going to be sticking around.

edit flag offensive delete link more

Comments

Hi, thank you. What you have mentioned is in C++. I see no such constructor is Java.

ocv_user gravatar imageocv_user ( 2016-01-15 04:48:28 -0600 )edit

Oh, my apologies. It looks like you will want to use either byte or short, depending on which your data actually is. There are put methods for both of those.

http://docs.opencv.org/java/3.1.0/

Tetragramm gravatar imageTetragramm ( 2016-01-15 07:03:24 -0600 )edit

Hi, yes thank you. I stored short[] into Mat successfully. Actually, in Java, short data type is signed. In fact java has only signed data type. But what I have stored in my short[] array, is 10-bit unsigned data. Hence, I wanted to use char[] which is the only unsigned type.

ocv_user gravatar imageocv_user ( 2016-01-15 07:50:34 -0600 )edit
1

Java is not my strong point, but it should be possible to copy the data into a short array bitwise, without doing a conversion. Then it may be called a short, but it's still the same data, and the Mat will treat it that way. The Mat will use it as unsigned short, because that's what you told it to do by declaring it CV_16U.

Also, 10 bits unsigned fit into a 16 bit signed comfortably.

Tetragramm gravatar imageTetragramm ( 2016-01-15 07:56:13 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-01-14 16:15:40 -0600

Seen: 290 times

Last updated: Jan 14 '16