android + java opencv + Mat与byte[]互换

    Mat mat1 = new Mat();

    try {
        mat1 = Utils.loadResource(this,R.drawable.testpic, 0);
    } catch (IOException e) {
        e.printStackTrace();
    }
    
    byte[] bytebuffer = new byte[mat1.height()  *  mat1.width()];
    mat1.get(0, 0, bytebuffer);
    Mat mat2 = new Mat(mat1.height(), mat1.width(), CV_8U);
    mat2.put(0, 0, bytebuffer);

参考:

https://blog.csdn.net/infinite2009/article/details/43086071

你可能感兴趣的:(Android)