Ask Your Question
1

How can I initialize Mat?

asked 2014-03-03 23:53:26 -0600

lingyun gravatar image

Mat gaborMat = new Mat(3, 3, CvType.CV_8UC1); float k[3][3] = { 1.0, -2.0, 1.0, 4.0, -2.0, -1.0, 4.0, -2.0, 2.0 } Hi! I am a fresh man here. Could I ask how I can initialize Mat with k[][]?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
3

answered 2014-03-04 01:24:59 -0600

berak gravatar image

since opencv wants consecutive data, you can't use a double [][]

float k[9] = { 1.0, -2.0, 1.0, 4.0, -2.0, -1.0, 4.0, -2.0, 2.0 };
Mat gaborMat = new Mat(3, 3, CvType.CV_32FC1); // note , the flag has to match the actual type ..
gaborMat.put(0,0,k);
edit flag offensive delete link more

Comments

I think opencv can handle that.

Moster gravatar imageMoster ( 2014-03-04 01:29:31 -0600 )edit

Thank you very much!

lingyun gravatar imagelingyun ( 2014-03-04 02:08:49 -0600 )edit
0

answered 2014-03-04 01:28:24 -0600

Moster gravatar image

updated 2014-03-04 01:39:22 -0600

Mat kMat = new Mat(3,3, CvType.CV_32FC1, k);

or if you dont actually need the k array(c++ only):

Mat kMat = (Mat_<float>(3,3) << 1.0, -2.0, 1.0, 4.0, -2.0, -1.0, 4.0, -2.0, 2.0);
edit flag offensive delete link more

Comments

Ok, your code is java. So, skip the 2nd one. This is c++ specific.

Moster gravatar imageMoster ( 2014-03-04 01:36:40 -0600 )edit

Question Tools

Stats

Asked: 2014-03-03 23:53:26 -0600

Seen: 3,910 times

Last updated: Mar 05 '14