将mat对象转换为float32[1,66200,3]android studio

kx1ctssn  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(211)

我试图在androidstudio上将mat对象转换为float32[1200,66,3],以满足我的tflite模型。

@Override
    public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

        Mat frame = inputFrame.rgba();
        Imgproc.cvtColor(frame, frame, Imgproc.COLOR_RGBA2RGB);
        Imgproc.cvtColor(frame, frame, Imgproc.COLOR_RGB2YUV);
        Imgproc.GaussianBlur(frame, frame, new Size(3, 3), 0, 0);
        Imgproc.resize(frame, frame, new Size(200, 66));
        frame.convertTo(frame, CV_32F);

        float[][] outputs = new float[1][1];
        float[][][][] inputs = new float[1][200][66][3]; //desired form to model

//
        interperter.run(inputs ,outputs);
        System.out.println("output: " + outputs[0][0]);

        return frame;
    }

转换垫架的正确方法是什么?
谢谢
编辑:就像一个魅力:

float[][][][] inputs = new float[1][200][66][3];
float fs[] = new float[3];
   for( int r=0 ; r<f.rows() ; r++ ) {
        for( int c=0 ; c<f.cols() ; c++ ) {
            f.get(r, c, fs);
            inputs[0][c][r][0]=fs[0]/255;
            inputs[0][c][r][1]=fs[1]/255;
            inputs[0][c][r][2]=fs[2]/255;
        }   
   }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题