Android OpenCV图像转换

    1.Mat存储到本地:

       

 public void saveMatData(Mat mat) {

        File fileDir = new File(Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_PICTURES), "mybook");
        if (!fileDir.exists()) {
            fileDir.mkdirs();
        }
        String name = String.valueOf(System.currentTimeMillis()) + "_book.jpg";
        File tempFile = new File(fileDir.getAbsoluteFile() + File.separator, name);
        Imgproc.cvtColor(mat, mat,Imgproc.COLOR_RGB2BGR);//保存到本地的颜色值,如果不转换默认是红色值,因为Mat默认是BGR格式
        Imgcodecs.imwrite(tempFile.getAbsolutePath(), mat);
        Log.e("存储", "FielSaveMatData" + tempFile.getPath());
  }

   

public void saveMatData(Mat mat) {
        File fileDir = new File(Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_PICTURES), "mybook");
        if (!fileDir.exists()) {
            fileDir.mkdirs();
        }
        String name = String.valueOf(System.currentTimeMillis()) + "_book.jpg";
        File tempFile = new File(fileDir.getAbsoluteFile() + File.separator, name);
        Mat dst = new Mat(mat.rows(), mat.cols(), CvType.CV_8UC4);    //新建目标输出图像
        Imgproc.cvtColor(mat, dst, Imgproc.COLOR_RGB2BGR);
        Imgcodecs.imwrite(tempFile.getAbsolutePath(), dst);
        Log.e("存储", "FielSaveMatData" + tempFile.getPath());
    }

  

Android OpenCV图像转换

上一篇:iOS 基础笔试题


下一篇:Python之路第一课Day9--随堂笔记之二(进程、线程、协程篇)