Java Code Examples for org.opencv.core.Mat#reshape()
The following examples show how to use
org.opencv.core.Mat#reshape() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Recognition.java From classchecks with Apache License 2.0 | 6 votes |
/** * * @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; }
Example 2
Source File: TestUtils.java From go-bees with GNU General Public License v3.0 | 6 votes |
/** * Checks if two OpenCV Mats are equal. * The matrices must be equal size and type. * Floating-point mats are not supported. * * @param expected expected mat. * @param actual actual mat. * @return true if they are equal. */ private static boolean equals(Mat expected, Mat actual) { if (expected.type() != actual.type() || expected.cols() != actual.cols() || expected.rows() != actual.rows()) { throw new UnsupportedOperationException( "Can not compare " + expected + " and " + actual); } else if (expected.depth() == CvType.CV_32F || expected.depth() == CvType.CV_64F) { throw new UnsupportedOperationException( "Floating-point mats must not be checked for exact match."); } // Subtract matrices Mat diff = new Mat(); Core.absdiff(expected, actual, diff); // Count non zero pixels Mat reshaped = diff.reshape(1); // One channel int mistakes = Core.countNonZero(reshaped); // Free reshaped.release(); diff.release(); // Check mistakes return 0 == mistakes; }
Example 3
Source File: Eigenfaces.java From Android-Face-Recognition-with-Deep-Learning-Library with Apache License 2.0 | 6 votes |
public String recognize(Mat img, String expectedLabel){ // Ignore img = img.reshape(1,1); // Subtract mean img.convertTo(img, CvType.CV_32F); Core.subtract(img, Psi, img); // Project to subspace Mat projected = getFeatureVector(img); // Save all points of image for tSNE img.convertTo(img, CvType.CV_8U); addImage(projected, expectedLabel, true); //addImage(projected, expectedLabel); Mat distance = new Mat(Omega.rows(), 1, CvType.CV_64FC1); for (int i=0; i<Omega.rows(); i++){ double dist = Core.norm(projected.row(0), Omega.row(i), Core.NORM_L2); distance.put(i, 0, dist); } Mat sortedDist = new Mat(Omega.rows(), 1, CvType.CV_8UC1); Core.sortIdx(distance, sortedDist, Core.SORT_EVERY_COLUMN + Core.SORT_ASCENDING); // Give back the name of the found person int index = (int)(sortedDist.get(0,0)[0]); return labelMap.getKey(labelList.get(index)); }
Example 4
Source File: Cluster.java From opencv-fun with GNU Affero General Public License v3.0 | 5 votes |
public static List<Mat> cluster(Mat cutout, int k) { Mat samples = cutout.reshape(1, cutout.cols() * cutout.rows()); Mat samples32f = new Mat(); samples.convertTo(samples32f, CvType.CV_32F, 1.0 / 255.0); Mat labels = new Mat(); TermCriteria criteria = new TermCriteria(TermCriteria.COUNT, 100, 1); Mat centers = new Mat(); Core.kmeans(samples32f, k, labels, criteria, 1, Core.KMEANS_PP_CENTERS, centers); return showClusters(cutout, labels, centers); }
Example 5
Source File: KNearestNeighbor.java From Android-Face-Recognition-with-Deep-Learning-Library with Apache License 2.0 | 4 votes |
@Override public Mat getFeatureVector(Mat img) { return img.reshape(1,1); }
Example 6
Source File: SupportVectorMachine.java From Android-Face-Recognition-with-Deep-Learning-Library with Apache License 2.0 | 4 votes |
public Mat getFeatureVector(Mat img){ return img.reshape(1,1); }