.subMat() does not cut the designated part of a Mat object

asked 2015-04-22 08:01:33 -0500

RB gravatar image

updated 2015-04-22 08:03:43 -0500

I am testing how to use Point and Rect classes inopencv with java API, i wrote the below code and as you see, pStart is (0,0) and pEnd(0+10, 0+10). the rectangle i created is of 10 width and 10 height. then i wanted to cut an area from a Mat object equal to the rect height and width as show i the code, but when i displayed the contents of the sub-mat, as you see below in the output, it is of 10 rows and more columns and i expected to have 10 rows and 10 columns.

please let me know what i am doing wrong

Code:

    Point pstart = new Point(0, 0);
    Log.D(TAG, "MainClass", "" + pstart.x);
    Log.D(TAG, "MainClass", "" + pstart.y);
    Point pEnd = new Point(pstart.x+10, pstart.y+10);
    Rect rec1 = new Rect(pstart, pEnd);

    Log.D(TAG, "MainClass", "" + rec1.height);
    Log.D(TAG, "MainClass", "" + rec1.width);
    Mat subMat = matFactory.getMatAt(0).submat(rec1);

    Log.D(TAG, "MainClass", "" + subMat.dump());

OutPut

Debug: MainClass -> MainClass: 0.0
5: Debug: MainClass -> MainClass: 0.0
6: Debug: MainClass -> MainClass: 10
7: Debug: MainClass -> MainClass: 10
8: Debug: MainClass -> MainClass: [0, 38, 46, 0, 38, 46, 0, 38, 46, 0, 37, 45, 0, 35, 40, 0, 32, 37, 0, 34, 40, 1, 37, 43, 1, 34, 43, 5, 38, 47;
    4, 45, 47, 0, 41, 43, 0, 38, 40, 0, 38, 40, 0, 39, 41, 0, 39, 41, 0, 38, 40, 0, 37, 39, 3, 38, 42, 5, 40, 44;
    12, 52, 51, 6, 46, 45, 2, 42, 40, 1, 41, 39, 3, 43, 41, 4, 44, 42, 3, 42, 40, 2, 41, 39, 1, 39, 39, 1, 39, 39;
    9, 48, 50, 6, 45, 47, 2, 41, 43, 0, 39, 41, 0, 38, 37, 0, 37, 36, 0, 37, 37, 1, 39, 39, 1, 39, 41, 2, 40, 42;
    13, 48, 58, 9, 44, 54, 5, 41, 49, 2, 38, 46, 0, 36, 44, 0, 35, 43, 0, 35, 43, 0, 37, 45, 0, 36, 46, 2, 38, 48;
    19, 52, 67, 11, 44, 59, 5, 38, 53, 4, 37, 52, 5, 39, 52, 5, 39, 52, 2, 37, 50, 0, 35, 48, 0, 34, 48, 2, 37, 51;
    16, 47, 62, 10, 41, 56, 3, 37, 50, 2, 36, 49, 4, 38, 51, 4, 38, 51, 1, 36, 49, 0, 35, 48, 0, 36, 50, 1, 38, 52;
    15, 47, 58, 13, 45, 56, 12, 44, 55, 10, 42, 53, 6, 41, 51, 5, 40, 50, 5, 41, 51, 8, 44, 54, 4, 42, 54, 5, 43, 55;
    19, 47, 64, 17, 45, 62, 13, 44, 59, 11, 42, 57, 8, 42, 55, 7, 41, 54, 5, 44, 53, 5, 44, 53, 3, 44, 53, 4, 44, 56;
    12, 41, 56, 12, 41, 56, 10, 41, 56, 9, 40, 55, 7, 41, 54, 8, 42, 55, 5, 44, 53, 5, 44, 53, 6, 44, 56, 6, 44, 56]
edit retag flag offensive close merge delete

Comments

1

looks all correct to me. you got 10 lines, each line has 10 pixels a 3 components (e.g. b,g,r)

berak gravatar imageberak ( 2015-04-22 08:08:57 -0500 )edit

oh, was it because it is RGB? i thought i should get 10 cols and 10 rows

RB gravatar imageRB ( 2015-04-22 08:15:45 -0500 )edit