Ask Your Question
0

Mat_<uchar> translation in java, dilating

asked 2013-10-12 14:19:37 -0500

sebastianrevan gravatar image

updated 2013-10-13 02:09:42 -0500

berak gravatar image

Hello, im trying to translate this c++ code to java Mat kernel = (Mat_<uchar>(3,3) << 0,1,0,1,1,1,0,1,0); dilate(outerBox, outerBox, kernel);

i figured up the dilate part, but i can't do the same with the Mat kernel object, i know that line is intended to create a 3x3 matrix of unsigned characters and fil it with 0,1,0,1,1,1,0,1,0 but i can't come up with the java equivalent of the Mat_<uchar> class, and i can't figure out how to assign 0,1,0,1,1,1,0,1,0 this vector to the matrix object

thanks in advance!

edit retag flag offensive close merge delete

Comments

1

byte [] data = {0,1,0,1,1,1,0,1,0}; Mat kernel = new Mat(3,3,CvType.CV_8U); kernel.put(0,0,data);

berak gravatar imageberak ( 2013-10-13 02:12:39 -0500 )edit

thanks a lot, that solved it, although i solved it by creating a 3x3 CV_8u matrix and putting the numbers one by one, you approach is much more elegant.

sebastianrevan gravatar imagesebastianrevan ( 2013-10-14 07:56:30 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-10-15 18:56:16 -0500

sebastianrevan gravatar image

i solved this by creating a 3x3 Mat and putting the data by myself

   Mat ukernel = new Mat(3, 3, CvType.CV_8U);
        ukernel.put(0, 0, (byte) 0);
        ukernel.put(0, 1, (byte) 1);
        ukernel.put(0, 2, (byte) 0);
        ukernel.put(1, 0, (byte) 1);
        ukernel.put(1, 1, (byte) 1);
        ukernel.put(1, 2, (byte) 1);
        ukernel.put(2, 0, (byte) 0);
        ukernel.put(2, 1, (byte) 1);
        ukernel.put(2, 2, (byte) 0);
        Imgproc.dilate(outerbox, outerbox, ukernel);
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-10-12 14:19:37 -0500

Seen: 829 times

Last updated: Oct 15 '13