Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Mat type CV_8U but ByteBuffer values range from -128 to 127

Hello guys,

I have a frame which has its type = 24. According to this table this means the frame is CV_8U, thus its values should be around 0 and 255.

I wanted to confirm that in fact the values I'm getting are 0-255, so I did the following: byte[] buff= new byte[frame.cols() * frame.rows() * 4]; //nº total de valores (3 canais)

    frame.get(0,0,buff);

    Log.d("frame type:","frame_type:"+frame.type());

    max_pixel=-100;
    min_pixel=100;
    for(int i=0; i<frame.cols(); i++) {
        for(int j=0; j<frame.cols(); j++) {
            if (buff[i]>max_pixel) {
                max_pixel=buff[i]; } //TODO: perceber pq é que a matriz varia entre -128 e 127 e não entre 0 e 255 (frame.type = 24, supostamente 8UC4 logo 0-255)
            else if(buff[i]<min_pixel){
                 min_pixel=buff[i];
            }
        }
    }
    Log.d("max_pixel", "max_pixel:"+max_pixel);
    Log.d("min_pixel", "min_pixel:"+min_pixel);

What I got from this was: (1) min_pixel = -128 (2) max_pixel = 127

Is this normal for a ByteBuffer? Because it seems like its type is a CV_8S instead

Thanks for the help!

Mat type CV_8U but ByteBuffer values range from -128 to 127

Hello guys,

I have a frame which has its type = 24. According to this table this means the frame is CV_8U, thus its values should be around 0 and 255.

I wanted to confirm that in fact the values I'm getting are 0-255, so I did the following: byte[] buff= new byte[frame.cols() * frame.rows() * 4]; //nº total de valores (3 canais)

    frame.get(0,0,buff);

    Log.d("frame type:","frame_type:"+frame.type());

    max_pixel=-100;
    min_pixel=100;
    for(int i=0; i<frame.cols(); i++) {
        for(int j=0; j<frame.cols(); j++) {
            if (buff[i]>max_pixel) {
                max_pixel=buff[i]; } //TODO: perceber pq é que a matriz varia entre -128 e 127 e não entre 0 e 255 (frame.type = 24, supostamente 8UC4 logo 0-255)
             else if(buff[i]<min_pixel){
                 min_pixel=buff[i];
            }
        }
    }
    Log.d("max_pixel", "max_pixel:"+max_pixel);
    Log.d("min_pixel", "min_pixel:"+min_pixel);

What I got from this was: (1) min_pixel = -128 (2) max_pixel = 127

Is this normal for a ByteBuffer? Because it seems like its type is a CV_8S instead

Thanks for the help!