Ask Your Question
1

How can I initialize Mat?

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

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 -0500

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 -0500 )edit

Thank you very much!

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

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

Moster gravatar image

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

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 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

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

Seen: 658 times

Last updated: Mar 05 '14