Java Code Examples for org.opencv.core.Core#gemm()

The following examples show how to use org.opencv.core.Core#gemm() . 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 5 votes vote down vote up
public static Mat subspaceProject(Mat W, Mat mean, Mat src) {
	int n = src.rows();
	int d = src.cols();
	Mat X = new Mat();
	Mat Y = new Mat();
	src.convertTo(X, W.type());
	if(!mean.empty()) {
		for(int i = 0; i < n; i ++) {
			Mat r_i = X.row(i);
			Core.subtract(r_i, mean.reshape(1, 1), r_i);
		}
	}
	Core.gemm(X, W, 1.0, new Mat(), 0.0, Y);
	return Y;
}
 
Example 2
Source File: Recognition.java    From classchecks with Apache License 2.0 5 votes vote down vote up
public static Mat subspaceReconstruct(Mat W, Mat mean, Mat src) {
	int n = src.rows();
	int d = src.cols();
	Mat X = new Mat();
	Mat Y = new Mat();
	src.convertTo(Y, W.type());
	Core.gemm(Y, W, 1.0, new Mat(), 0.0, X, 2);
	if(!mean.empty()) {
		for(int i = 0; i < n; i ++) {
			Mat r_i = X.row(i);
			Core.add(r_i, mean.reshape(1, 1), r_i);
		}
	}
	return X;
}
 
Example 3
Source File: MatOperation.java    From Android-Face-Recognition-with-Deep-Learning-Library with Apache License 2.0 5 votes vote down vote up
public static Rect[] rotateFaces(Mat img, Rect[] faces, int angle){
    Point center = new Point(img.cols()/2, img.rows()/2);
    Mat rotMat = Imgproc.getRotationMatrix2D(center, angle, 1);
    rotMat.convertTo(rotMat, CvType.CV_32FC1);
    float scale = img.cols()/img.rows();
    for(Rect face : faces){
        Mat m = new Mat(3, 1, CvType.CV_32FC1);
        m.put(0,0,face.x);
        m.put(1,0,face.y);
        m.put(2,0,1);
        Mat res = Mat.zeros(2,1,CvType.CV_32FC1);
        Core.gemm(rotMat, m, 1, new Mat(), 0, res, 0);
        face.x = (int)res.get(0,0)[0];
        face.y = (int)res.get(1,0)[0];
        if(angle == 270 || angle == -90){
            face.x = (int)(face.x * scale - face.width);
            face.x = face.x + face.width/4;
            face.y = face.y + face.height/4;
        }else if(angle == 180 || angle == -180){
            face.x = face.x - face.width;
            face.y = face.y - face.height;
        }else if(angle == 90 || angle == -270){
            face.y = (int)(face.y * scale - face.height);
            face.x = face.x - face.width/4;
            face.y = face.y - face.height/4;
        }
    }
    return faces;
}