本文整理匯總了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;
}