package com.csdn.linghu.javacvlean03;
import org.bytedeco.javacpp.opencv_core.CvMat;
import static org.bytedeco.javacpp.opencv_core.*;
public class ReadWriteCVMat {
public static void main(String[] args) {
//创建5X5的矩阵,元素类型是32位浮点型
CvMat writeCvMat = cvCreateMat(5, 5, CV_32FC1);
//设置第四行,第四列元素为4.0
cvmSet(writeCvMat,4,4,4.0);
//设置第三行,第三列元素为3.0
cvSetReal2D(writeCvMat,3,3,3.0);
//将矩阵保存到xml文件中
cvSave("resources/CvMat.xml", writeCvMat);
//从XML文件中,读取数据,并填充到一个矩阵中
CvMat readCvMat = new CvMat(cvLoad("resources/CvMat.xml")) ;
System.out.println(readCvMat.toString());
}
}
结果: