/** * Extract col to provided array. * * @param col * @param array */ public void getColumn(int col, double[] array) { for (int j = 0; j < array.length; j++) { array[j] = mat.get(j, col); } }
/** * Returns the value at the row, column position in the matrix. * * @param row * @param column * @return Matrix value at the given row and column. */ @Override public double getElement(int row, int column) { return mat.get(row, column); }
/** * Extract row to provided array * * @param row * @param array */ public void getRow(int row, double[] array) { for (int i = 0; i < array.length; i++) { array[i] = mat.get(row, i); } }
/** * Extracts the linear constraint matrix for case 1 from the full 6x10 constraint matrix. */ public static void constraintMatrix3x3a( DMatrixRMaj L_3x6 , DMatrixRMaj L_3x3 ) { int index = 0; for( int i = 0; i < 3; i++ ) { L_3x3.data[index++] = L_3x6.get(i,0); L_3x3.data[index++] = L_3x6.get(i,1); L_3x3.data[index++] = L_3x6.get(i,2); } }
/** * Returns location of 3D feature for a view * @param feature Index of feature to retrieve * @param out (Output) Storage for 3D feature. homogenous coordinates */ public void getFeature3D( int feature , Point4D_F64 out ) { out.x = X.get(0,feature); out.y = X.get(1,feature); out.z = X.get(2,feature); out.w = X.get(3,feature); }
public void computeJacobian( Point2D_F64 x1 , Point2D_F64 x2 ) { J.data[0] = -H.get(1,0) + x2.y*H.get(2,0); J.data[1] = -H.get(1,1) + x2.y*H.get(2,1); J.data[2] = 0; J.data[3] = x1.x*H.get(2,0) + x1.y*H.get(2,1) + H.get(2,2); J.data[4] = H.get(0,0) - x2.x*H.get(2,0); J.data[5] = H.get(0,1) - x2.x*H.get(2,1); J.data[6] = -J.data[3]; J.data[7] = 0; }
/** * Extracts the linear constraint matrix for case 2 from the full 6x10 constraint matrix. */ public static void constraintMatrix6x3( DMatrixRMaj L_6x10 , DMatrixRMaj L_6x3 ) { int index = 0; for( int i = 0; i < 6; i++ ) { L_6x3.data[index++] = L_6x10.get(i,0); L_6x3.data[index++] = L_6x10.get(i,1); L_6x3.data[index++] = L_6x10.get(i,4); } }
@Override public void initialize(DMatrixRMaj K , double[] radial) { intrinsic.fx = K.get(0,0); intrinsic.fy = K.get(1,1); intrinsic.skew = assumeZeroSkew ? 0 : K.get(0,1); intrinsic.cx = K.get(0,2); intrinsic.cy = K.get(1,2); if( radial.length != intrinsic.radial.length ) throw new RuntimeException("BUG!"); System.arraycopy(radial,0,intrinsic.radial,0,intrinsic.radial.length); intrinsic.t1 = intrinsic.t2 = 0; }
public static CameraPinhole matrixToPinhole(DMatrixRMaj K , int width , int height , CameraPinhole output ) { if( output == null ) output = new CameraPinhole(); output.fx = K.get(0,0); output.fy = K.get(1,1); output.skew = K.get(0,1); output.cx = K.get(0,2); output.cy = K.get(1,2); output.width = width; output.height = height; return output; }
public boolean isZero( int x1 , int x2 ) { // this provides a relative threshold for when dealing with very large/small numbers double target = Math.abs(A.get(x1,x2)); double above = Math.abs(A.get(x1-1,x2)); // according to Matrix Computations page 352 this is what is done in Eispack double right = Math.abs(A.get(x1,x2+1)); return target <= 0.5*UtilEjml.EPS*(above+right); }
public static Point2D_F64 convertNormToPixel( DMatrixRMaj K, Point2D_F64 norm , Point2D_F64 pixel ) { if( pixel == null ) pixel = new Point2D_F64(); PinholeNtoP_F64 alg = new PinholeNtoP_F64(); alg.set(K.get(0,0),K.get(1,1),K.get(0,1),K.get(0,2),K.get(1,2)); alg.compute(norm.x,norm.y,pixel); return pixel; }
public static Point2D_F64 convertPixelToNorm( DMatrixRMaj K , Point2D_F64 pixel , Point2D_F64 norm ) { if( norm == null ) norm = new Point2D_F64(); PinholePtoN_F64 alg = new PinholePtoN_F64(); alg.set(K.get(0,0),K.get(1,1),K.get(0,1),K.get(0,2),K.get(1,2)); alg.compute(pixel.x,pixel.y,norm); return norm; }
@Override public DMatrixRMaj getB(DMatrixRMaj B, boolean compact) { B = BidiagonalDecompositionRow_DDRM.handleB(B, compact, m, n, min); B.set(0,0,this.B.get(0,0)); for( int i = 1; i < min; i++ ) { B.set(i,i, this.B.get(i,i)); B.set(i-1,i, this.B.get(i-1,i)); } if( n > m) B.set(min-1,min,this.B.get(min-1,min)); return B; }
@Override public void getDiagonal(double[] diag, double[] off) { diag[0] = UBV.get(0); for( int i = 1; i < n; i++ ) { diag[i] = UBV.unsafe_get(i,i); off[i-1] = UBV.unsafe_get(i-1,i); } }
@Override public void getDiagonal(double[] diag, double[] off) { diag[0] = B.get(0); for( int i = 1; i < n; i++ ) { diag[i] = B.unsafe_get(i,i); off[i-1] = B.unsafe_get(i-1,i); } }
public static Mat toMat(DMatrixRMaj in ) { Mat out = new Mat(in.numRows,in.numCols,CV_64F); DoubleRawIndexer indexer = out.createIndexer(); for (int i = 0; i < in.numRows; i++) { for (int j = 0; j < in.numCols; j++) { indexer.put(i,j, in.get(i,j)); } } return out; }
@Test public void setMean() { GaussianGmm_F64 g = new GaussianGmm_F64(3); g.setMean(new double[]{1,2,3}); for (int i = 0; i < 3; i++) { assertEquals(i+1,g.mean.get(i,0),1e-8); } }
@Test public void setDiagonals() { DMatrixRMaj M = RandomMatrices_DDRM.rectangle(6,6,rand); setHessian(alg,M); DMatrixRMaj v = RandomMatrices_DDRM.rectangle(6,1,rand); alg.setDiagonals(v); DMatrixRMaj found = RandomMatrices_DDRM.rectangle(6,1,rand); alg.extractDiagonals(found); for (int i = 0; i < M.numRows; i++) { assertEquals(found.get(i),v.get(i), UtilEjml.TEST_F64); } }