本文整理汇总了Java中org.opencv.core.CvException类的典型用法代码示例。如果您正苦于以下问题:Java CvException类的具体用法?Java CvException怎么用?Java CvException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CvException类属于org.opencv.core包,在下文中一共展示了CvException类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: exportResource
import org.opencv.core.CvException; //导入依赖的package包/类
public static String exportResource(Context context, int resourceId, String dirname) {
String fullname = context.getResources().getString(resourceId);
String resName = fullname.substring(fullname.lastIndexOf("/") + 1);
try {
InputStream is = context.getResources().openRawResource(resourceId);
File resDir = context.getDir(dirname, Context.MODE_PRIVATE);
File resFile = new File(resDir, resName);
FileOutputStream os = new FileOutputStream(resFile);
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = is.read(buffer)) != -1) {
os.write(buffer, 0, bytesRead);
}
is.close();
os.close();
return resFile.getAbsolutePath();
} catch (IOException e) {
e.printStackTrace();
throw new CvException("Failed to export resource " + resName
+ ". Exception thrown: " + e);
}
}
示例2: reconstructFace
import org.opencv.core.CvException; //导入依赖的package包/类
/**
*
* @Title: reconstructFace
* @Description: 从输入的预处理图像在人脸模型中重构人脸
* @param model 包含预处理的人脸模型
* @param preprocessedFace 输入的预处理过的图像
* @return
* Mat
* @throws
*/
public static Mat reconstructFace(BasicFaceRecognizer model, Mat preprocessedFace){
try {
// 获取每个人脸的特征值
Mat eigenvectors = model.getEigenVectors();
// 获取平均人脸
Mat averageFaceRow = model.getMean();
int faceHeight = preprocessedFace.rows();
// subspaceProject将人脸图像投影到特征空间
Mat projection = subspaceProject(eigenvectors, averageFaceRow, preprocessedFace.reshape(1, 1));
// subspaceReconstruct从特征空间重构图像
Mat reconstructionRow = subspaceReconstruct(eigenvectors, averageFaceRow, projection);
Mat reconstructionMat = reconstructionRow.reshape(1, faceHeight);
Mat reconstructedFace = new Mat(reconstructionMat.size(), CvType.CV_8U);
reconstructionMat.convertTo(reconstructedFace, CvType.CV_8U, 1, 0);
return reconstructedFace;
} catch(CvException e) {
e.printStackTrace();
}
return null;
}