parent
bb91041b42
commit
f14fb57468
@ -1,64 +0,0 @@
|
||||
package org.wlld.imageRecognition;
|
||||
|
||||
import org.wlld.MatrixTools.Matrix;
|
||||
import org.wlld.MatrixTools.MatrixOperation;
|
||||
import org.wlld.tools.ArithUtil;
|
||||
|
||||
/**
|
||||
* @author lidapeng
|
||||
* @description K均值聚类矩阵
|
||||
* @date 9:05 上午 2020/2/1
|
||||
*/
|
||||
public class KMatrix {
|
||||
private Matrix sigmaMatrix;//矩阵和
|
||||
private int nub;//加和次数
|
||||
private boolean isFinish = false;//是否结算
|
||||
|
||||
KMatrix(int x, int y) {
|
||||
sigmaMatrix = new Matrix(x, y);
|
||||
}
|
||||
|
||||
public boolean isFinish() {
|
||||
return isFinish;
|
||||
}
|
||||
|
||||
public void setFinish(boolean finish) {
|
||||
isFinish = finish;
|
||||
}
|
||||
|
||||
public Matrix getSigmaMatrix() {
|
||||
return sigmaMatrix;
|
||||
}
|
||||
|
||||
public double getEDist(Matrix matrix) throws Exception {//返回欧式距离
|
||||
if (isFinish && matrix.getX() == sigmaMatrix.getX()
|
||||
&& matrix.getY() == sigmaMatrix.getY()) {
|
||||
double sigma = 0;
|
||||
for (int i = 0; i < matrix.getX(); i++) {
|
||||
for (int j = 0; j < matrix.getY(); j++) {
|
||||
double sub = ArithUtil.sub(matrix.getNumber(i, j), sigmaMatrix.getNumber(i, j));
|
||||
sigma = ArithUtil.add(Math.pow(sub, 2), sigma);
|
||||
}
|
||||
}
|
||||
sigma = Math.sqrt(sigma);
|
||||
return sigma;
|
||||
} else {
|
||||
throw new Exception("K is not finish or matrix not equal");
|
||||
}
|
||||
}
|
||||
|
||||
public void addMatrix(Matrix matrix) throws Exception {
|
||||
sigmaMatrix = MatrixOperation.add(sigmaMatrix, matrix);
|
||||
nub++;
|
||||
}
|
||||
|
||||
public void getK() throws Exception {//结算K均值
|
||||
if (nub != 0) {
|
||||
double aNub = ArithUtil.div(1, nub);
|
||||
MatrixOperation.mathMul(sigmaMatrix, aNub);
|
||||
isFinish = true;
|
||||
} else {
|
||||
throw new Exception("not value");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
package org.wlld.imageRecognition.border;
|
||||
|
||||
import org.wlld.MatrixTools.Matrix;
|
||||
|
||||
/**
|
||||
* @author lidapeng
|
||||
* @description
|
||||
*
|
||||
* @date 8:49 上午 2020/1/24
|
||||
*/
|
||||
public class BorderBody {
|
||||
private Matrix xW;//平移X权重
|
||||
private Matrix yW;//平移Y权重
|
||||
private Matrix wW;//缩放宽度权重
|
||||
private Matrix hW;//缩放高度权重
|
||||
private Matrix x;//参数矩阵
|
||||
private Matrix tx;//X轴偏移量
|
||||
private Matrix ty;//Y轴偏移量
|
||||
private Matrix tw;//W缩放量
|
||||
private Matrix th;//H缩放量
|
||||
|
||||
public Matrix getxW() {
|
||||
return xW;
|
||||
}
|
||||
|
||||
public void setxW(Matrix xW) {
|
||||
this.xW = xW;
|
||||
}
|
||||
|
||||
public Matrix getyW() {
|
||||
return yW;
|
||||
}
|
||||
|
||||
public void setyW(Matrix yW) {
|
||||
this.yW = yW;
|
||||
}
|
||||
|
||||
public Matrix getwW() {
|
||||
return wW;
|
||||
}
|
||||
|
||||
public void setwW(Matrix wW) {
|
||||
this.wW = wW;
|
||||
}
|
||||
|
||||
public Matrix gethW() {
|
||||
return hW;
|
||||
}
|
||||
|
||||
public void sethW(Matrix hW) {
|
||||
this.hW = hW;
|
||||
}
|
||||
|
||||
public Matrix getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(Matrix x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public Matrix getTx() {
|
||||
return tx;
|
||||
}
|
||||
|
||||
public void setTx(Matrix tx) {
|
||||
this.tx = tx;
|
||||
}
|
||||
|
||||
public Matrix getTy() {
|
||||
return ty;
|
||||
}
|
||||
|
||||
public void setTy(Matrix ty) {
|
||||
this.ty = ty;
|
||||
}
|
||||
|
||||
public Matrix getTw() {
|
||||
return tw;
|
||||
}
|
||||
|
||||
public void setTw(Matrix tw) {
|
||||
this.tw = tw;
|
||||
}
|
||||
|
||||
public Matrix getTh() {
|
||||
return th;
|
||||
}
|
||||
|
||||
public void setTh(Matrix th) {
|
||||
this.th = th;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue