public static void main(String[] args) { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); // Mat mat = Mat.eye( 3, 3, CvType.CV_8UC1 ); // System.out.println( "mat = " + mat.dump() ); Sample n = new Sample(); // n.templateMatching(); // put text in image // Mat data= Highgui.imread("images/erosion.jpg"); // Core.putText(data, "Sample", new Point(50,80), Core.FONT_HERSHEY_SIMPLEX, 1, new // Scalar(0,0,0),2); // // Highgui.imwrite("images/erosion2.jpg", data); // getting dct of an image String path = "images/croppedfeature/go (20).jpg"; path = "images/wordseg/img1.png"; Mat image = Highgui.imread(path, Highgui.IMREAD_GRAYSCALE); ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>(); Imgproc.threshold(image, image, 0, 255, Imgproc.THRESH_OTSU); Imgproc.threshold(image, image, 220, 128, Imgproc.THRESH_BINARY_INV); Mat newImg = new Mat(45, 100, image.type()); newImg.setTo(new Scalar(0)); n.copyMat(image, newImg); int vgap = 25; int hgap = 45 / 3; Moments m = Imgproc.moments(image, false); Mat hu = new Mat(); Imgproc.HuMoments(m, hu); System.out.println(hu.dump()); // //divide the mat into 12 parts then get the features of each part // int count=1; // for(int j=0; j<45; j+=hgap){ // for(int i=0;i<100;i+=vgap){ // Mat result = newImg.submat(j, j+hgap, i, i+vgap); // // // Moments m= Imgproc.moments(result, false); // double m01= m.get_m01(); // double m00= m.get_m00(); // double m10 = m.get_m10(); // int x= m00!=0? (int)(m10/m00):0; // int y= m00!=0? (int)(m01/m00):0; // Mat hu= new Mat(); // Imgproc.HuMoments(m, hu); // System.out.println(hu.dump()); // System.out.println(count+" :"+x+" and "+y); // Imgproc.threshold(result, result, 0,254, Imgproc.THRESH_BINARY_INV); // Highgui.imwrite("images/submat/"+count+".jpg", result); // count++; // // } // } // // for(int i=vgap;i<100;i+=vgap){ // Point pt1= new Point(i, 0); // Point pt2= new Point(i, 99); // Core.line(newImg, pt1, pt2, new Scalar(0,0,0)); // } // for(int i=hgap;i<45;i+=hgap){ // Point pt1= new Point(0, i); // Point pt2= new Point(99, i); // Core.line(newImg, pt1, pt2, new Scalar(0,0,0)); // } // Highgui.imwrite("images/submat/copyto.jpg", newImg); }