Vertical projection
Private org.opencv.core.Mat projectionVerticality (org.opencv.core.Mat MAT) { org.opencv.core.Mat projectionMat = mat.clone (); // Quxianjiuguo capture as a MAT projectionMat.setTo ( new new ORG .opencv.core.Scalar (255)); // then put into a white color Double [] = dotList new new Double [mat.cols ()]; // Create a list for storing the number of black dots in each column System .loadLibrary (Core.NATIVE_LIBRARY_NAME); System.out.println (mat.dump ()); int COL = mat.cols (); int Row = mat.rows (); for ( int X = 0; X <COL; x ++) { dotList[x] = 0.0; for (int y = 0; y < row; y++) { double binData = mat.get(y, x)[0]; if (binData == 0) {//黑色 dotList[x]++; } } } //然后生成投影图 for (int x = 0; x < mat.cols(); x++) { for (int y = 0; y < mat.rows(); y++) { if (x == 147) { System.out.println ( "Error will next line" ); } IF (Y < dotList [X]) { projectionMat.put (Y, X, 0 ); System.out.println (X + "column" + y + "OK" ); } } } return projectionMat; }
Horizontal projection
Private org.opencv.core.Mat projectionHorizontal (MAT org.opencv.core.Mat) { org.opencv.core.Mat projectionMat = mat.clone (); // Quxianjiuguo capture as a MAT projectionMat.setTo ( new new ORG .opencv.core.Scalar (255)); // then put into a white color Double [] = dotList new new Double [mat.rows ()]; // Create a list for storing the number of black dots in each column System .loadLibrary (Core.NATIVE_LIBRARY_NAME); System.out.println (mat.dump ()); int COL = mat.cols (); int Row = mat.rows (); for ( int Y = 0; Y <Row; y ++) { dotList[y] = 0.0; for (int x = 0; x < col; x++) { double binData = mat.get(y, x)[0]; if (binData == 0) {//黑色 dotList[y]++; } } } //然后生成投影图 for (int y = 0; y < mat.rows(); y++) { for (int x = 0; x < mat.cols(); x++) { try { IF (X < dotList [Y]) { projectionMat.put (Y, X, 0 ); } } the catch (Exception E) { System.out.println ( "Processing of:" + y + "th," + x + "columns" ); } } } return projectionMat; }