/* StartAndEndPoint l1 = parseArray[i]; StartAndEndPoint l2 = parseArray[i+ 1]; //CHECK WHICH line starts after the other //If l1 is starting after, then comparisons are based around l1.s //System.out.println("l1: " + l1.getP1().x); //System.out.println("l2: " + l2.getP1().x); System.out.println("1.0: L1S: " + l1.getP1().x + " larger than L2S: " + l2.getP1().x); if(l1.getP1().x > l2.getP1().x) { System.out.println("1.1: Comparing L1S: " + l1.getP1().x + " less than L2E: " + l2.getP2().x); if (l1.getP1().x < l2.getP2().x) { //AND System.out.println("1.2: Comparing L1S: " + l1.getP1().x + " larger than L2S: " + l2.getP1().x); if (l1.getP1().x > l2.getP1().x) { System.out.println("1: Success. NEXT"); //IT IS INTERSECTED continue; } else { //FAILED SECOND COMPARISON System.out.println("1: Fail"); } } else { System.out.println("Checking other line"); } System.out.println("2.0: L2S: " + l2.getP1().x + " larger than L1S: " + l1.getP1().x); } //If l2 is starting after, then comparisons are based around l2.s else if(l2.getP1().x > l1.getP1().x) { System.out.println("2.1: Comparing L2S: " + l1.getP1().x + " less than L1E: " + l2.getP2().x); if (l2.getP1().x < l1.getP2().x) { //AND System.out.println("2.2: Comparing L2S: " + l2.getP1().x + " larger than L1S: " + l1.getP1().x); if (l2.getP1().x > l1.getP1().x) { System.out.println("2: Success"); //IT IS INTERSECTED //continue; } else { //FAILED SECOND COMPARISON System.out.println("2: Fail"); //return false; } } else { System.out.println("Failed second comparison RETURN FALSE"); return false; } //return false; } else{ System.out.println("NEITHER RETURN FALSE"); return false; } */ import org.opencv.core.*; import org.opencv.core.Point; import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; import org.opencv.photo.Photo; import static org.opencv.imgcodecs.Imgcodecs.imwrite; import java.awt.image.BufferedImage; import java.awt.image.DataBufferByte; import java.io.File; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import javax.imageio.ImageIO; //REFERENCES: //https://docs.opencv.org/3.4.3/d9/db0/tutorial_hough_lines. //https://stackoverflow.com/questions/43443309/count-red-pixel-in-a-given-image //https://www.wikihow.com/Calculate-Percentage-in-Java //https://riptutorial.com/opencv/example/21963/converting-an-mat-object-to-an-bufferedimage-object //https://beginnersbook.com/2013/12/java-arraylist-of-object-sort-example-comparable-and-comparator/ //https://www.programiz.com/java-programming/examples/standard-deviation //https://www.geeksforgeeks.org/how-to-remove-duplicates-from-arraylist-in-java/ //https://stackoverflow.com/questions/7988486/how-do-you-calculate-the-variance-median-and-standard-deviation-in-c-or-java/7988556 //https://stackoverflow.com/questions/10396970/sort-a-list-that-contains-a-custom-class //GOAL for 21st //Classifier 01 //Have args so can call "java image-identification-classifier01 XX XX" //args can be parameters in algorthim such as threshold or theta? //Run on 5000 images. //Record success rates //All done with makefile //But first understand houghline transform //Know what the algorithm being used is doing. //MAke constants for this classifier //Make java be able to run on CMD line public class Main { //GLOBAL_CONSTANTS static double CLUSTER_DISTANCE_MAX = 40; static double CLUSTER_DISTANCE_MIN = 2; static int CLASSIFIER_HOUGHLINESP_MIN = 10; static int CLASSIFIER_HOUGHLINESP_MAX = 65; static int HOUGHLINEP_THRESHOLD = 10; static int STANDARD_DEVIATION_THRESHOLD = 6; static int MINLINECOUNT = 40; static int MAXLINEGAP = 1; //4 static double SLOPEGRADIENT = 0.02; //DEPENDENT FUNCTIONS AND CLASSES static class StartAndEndPoint { //PRIVATES private Point _p1; private Point _p2; //CONSTRUCTOR public StartAndEndPoint(Point p1, Point p2){ _p1 = p1; _p2 = p2; } //GETTERS public Point getP1(){ return _p1; } public Point getP2(){ return _p2; } //SETTERS public void setP1(Point p1){ _p1 = p1; } public void setP2(Point p2){ _p2 = p2; } //ToString public String toString(){ return "Start: " + _p1 + " End: " + _p2; } } public static ArrayList removeDuplicates(ArrayList list) { //DIRECTLY COPIED//DIRECTLY COPIED//DIRECTLY COPIED//DIRECTLY COPIED//DIRECTLY COPIED//DIRECTLY COPIED // Function to remove duplicates from an ArrayList // Create a new ArrayList ArrayList newList = new ArrayList(); // Traverse through the first list for (T element : list) { // If this element is not present in newList // then add it if (!newList.contains(element)) { newList.add(element); } } // return the new list return newList; //DIRECTLY COPIED//DIRECTLY COPIED//DIRECTLY COPIED//DIRECTLY COPIED//DIRECTLY COPIED//DIRECTLY COPIED } public static double StandardDeviation(double parseArray[]) { double mean; double sum =0.0; double standardDeviation = 0.0; //calculate sum of array for(int i =0; i < parseArray.length; i++){ sum += parseArray[i]; } //calculate mean of array mean = sum/parseArray.length; //calculate SD of array for(int j =0; j < parseArray.length; j++){ standardDeviation += Math.pow(parseArray[j]-mean, 2); } return Math.sqrt(standardDeviation/parseArray.length); } public static double VarianceCalc(StartAndEndPoint parseArray[]){ double sum =0; double temp =0; double mean, variance; int size = parseArray.length; //Calculate sum of array for(int i =0; i < parseArray.length; i++){ sum += parseArray[i].getP1().y; } //Calculate mean of array mean = sum/parseArray.length; //Calculate variants for(int i =0; i < size; i++){ temp += Math.pow((parseArray[i].getP1().y-mean),2); } variance = Math.abs(temp/(size -1)); //System.out.println("VARIANCE: " + variance); return variance; } public static Boolean lineComparison(double baseLineS, double compareLineS, double compareLineE ){ //System.out.print("Comparing baseLineS: " + baseLineS + " with compareLineE: " + compareLineE + " and compareLineS: " + compareLineS); if(baseLineS < compareLineE && baseLineS > compareLineS){ return true; } return false; } public static Boolean ClusterCheck(StartAndEndPoint parseArray[]){ try { //System.out.println("LENGTH: " + parseArray.length); //MAKE THREE COMPARISONS //After clusters have been found. //Check if their x positions intersect //Logic being //(L1.S < L2.E && L1.S > L2.S) //or //(L2.S < L1.E && L2.S > L1.S) //Variance is using Start of line point. //USING VARIANTS double variance = VarianceCalc(parseArray); Boolean consistent = false; if (variance <= CLUSTER_DISTANCE_MAX && variance > CLUSTER_DISTANCE_MIN) { for (int i = 0; i < parseArray.length - 1; i++) { //System.out.println(i); double l1_S = parseArray[i].getP1().x; double l1_E = parseArray[i].getP2().x; double l2_S = parseArray[i + 1].getP1().x; double l2_E = parseArray[i + 1].getP2().x; //Check which starts after if (l1_S >= l2_S) { //baseLineStart is l1_S (call with lineComparison) consistent = lineComparison(l1_S, l2_S, l2_E); } else if (l2_S > l1_S) { //baseLineStart is l2_S (call with lineComparison) consistent = lineComparison(l2_S, l1_S, l1_E); } else { System.err.println("An error, comparing l1_S and l2_S, has occurred"); } //Check if false was returned; if (consistent == false) { /*System.out.print(" X positions of two lines did not overlap each other:" + '\t'); System.out.print("l1_S: " + l1_S + '\t'); System.out.print("l1_E: " + l1_E + '\t'); System.out.print("l2_S: " + l2_S + '\t'); System.out.print("l2_E: " + l2_E); System.out.println(" ");*/ return false; } } //Have been through for loop, maintaining consistent being true. //Have also meet the variance MIN and MAX requirement. Therefore it is a cluster return true; } //System.out.println("Did not meet Cluster Distance Min and Max requirements, Variance = " + variance); return false; } catch (Exception e){ System.err.println(" "+e.getMessage()); return false; } } //CLASSIFYING FUNCTIONS private static BufferedImage toBufferedImage(Mat mat){ //MOSTLY COPY PASTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //MOSTLY COPY PASTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //https://riptutorial.com/opencv/example/21963/converting-an-mat-object-to-an-bufferedimage-object try{ int type = BufferedImage.TYPE_3BYTE_BGR; int bufferSize = mat.channels() * mat.cols() * mat.rows(); byte[] b = new byte[bufferSize]; //get all the pixels mat.get(0, 0, b); BufferedImage image = new BufferedImage(mat.cols(), mat.rows(), type); final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); System.arraycopy(b, 0, targetPixels, 0, b.length); return image; } catch(Exception e){ System.err.println(e); } return null; } private static boolean ClassifierPixelCount(BufferedImage img){ try { //Read file //BufferedImage img = ImageIO.read(new File(processedFile)); int x = img.getWidth(); int y = img.getHeight(); int pixelCount = 0; int redCount = 0; float percentage = 0; //Go Thru every pixel for(int i=0; i < y; i++){ for(int j=0;j < x; j++){ //Get value for current pixels RGB value int currPixelRGB = img.getRGB(j, i); //Check if pixel is red (hex value of red) if(currPixelRGB == 0xFFFF0000){ redCount++; } pixelCount++; } } //Calculate percentage of Red in image percentage = ((float)redCount/(float)pixelCount)*(float)100; //If more than %10 and less than %50 then its sheet music! if(percentage > CLASSIFIER_HOUGHLINESP_MIN && percentage < CLASSIFIER_HOUGHLINESP_MAX){ //MAKE THESE CONSTANTS!! return true;} } catch (Exception e) { System.err.println(e); } return false; } private static boolean ClassifierLineCount(int lineCount){ if(lineCount>MINLINECOUNT){ return true; } else{ return false; } } private static ArrayList ClassifierLineClusterOLD(BufferedImage img){ ArrayList returnArray = new ArrayList(); try { //IF THIS WORKS THEN IMPLEMENT A VERSION THAT USES POINTS from the draw line code. //ALSO CHECK OUT K NEAREST NEIGHBOR? //0xFFFF0000 = RED //go thru every pixel until find red pixel //get y pos of red pixel //continue with loop until find another red pixel //get y pos of red pixel //compare y pos (if close together then continue loop) else break int x = img.getWidth(); int y = img.getHeight(); int closeLineCount = 0; ArrayList redPixelYpos = new ArrayList(); //Go Thru every pixel for(int i=0; i < y; i++){ for(int j=0;j < x; j++){ //Get value for current pixels RGB value int currPixelRGB = img.getRGB(j, i); //Check if pixel is red (hex value of red) if(currPixelRGB == 0xFFFF0000) { //Store y pos of red pixel if there is no duplicate if(!redPixelYpos.contains(i)){ redPixelYpos.add(i); //System.out.println(i ); } } } } //Check if any of the lines found are close together and that there has been more than one line found if(redPixelYpos.size()>1){ //go through list and compare every value for(int i =0; i< redPixelYpos.size(); i++){ //System.out.println("i: " +redPixelYpos.get(i)); for(int j=0; j< redPixelYpos.size(); j++){ //System.out.println("j: "+redPixelYpos.get(j)); //Check if difference is less than 4 and the values are not duplicates. if(Math.abs(redPixelYpos.get(i) - redPixelYpos.get(j)) < 4 && !redPixelYpos.get(j).equals(redPixelYpos.get(i))){ closeLineCount++; } } } } int clusterCount = closeLineCount/4; if(closeLineCount >= 4){ returnArray.add(true); returnArray.add(closeLineCount); returnArray.add(clusterCount); } else{ returnArray.add(false); returnArray.add(closeLineCount); returnArray.add(clusterCount); } } catch (Exception e) { System.err.println(e); } return returnArray; } private static ArrayList ClassifierLineCluster(ArrayList linePointsArray, Mat clustersFoundRGB){ /* ADDITION: After clusters have been found. Check if x positions intersect at all StartXPos of p1 This will check for a cluster of lines that are close together. 1. Go through the list of Y positions(start point) in parsed array. If, there is a small distance between them, then, add to closeLineArray. Have all Y positions that are close to each other now. Need to find the lines that are clustered together. Now check if there are four of these are close to each other. 2. Go through list of closeLine. Get first four lines, traversing down a step each iteration {0,1,2,3} -> {1,2,3,4} -> {2,3,4,5} If, those 4 lines are close together, Then, add them to a new array that holds Line Cluster Values. Go to line 4 positions down since, as do not want duplicates. 3. */ ArrayList returnArray = new ArrayList(); ArrayList closeLineYPos = new ArrayList(); ArrayList clusterArray = new ArrayList(); int clusterCount = 0; try { if(linePointsArray.size()> 1) { /* //Display input array TESTING PURPOSES for (int i = 0; i < linePointsArray.size(); i++) { System.out.println(linePointsArray.get(i).toString()); } */ //1. Check if y points are close together //go thru list and compare values against each other for (int i = 0; i < linePointsArray.size(); i++){ //System.out.println("i: "+ linePointsArray.get(i).getP1().y); for (int j = 0; j < linePointsArray.size(); j++) { //System.out.println("j: "+ linePointsArray.get(j).getP1().y); //Check if difference is less than 4 and the values are not duplicates. if(Math.abs(linePointsArray.get(j).getP1().y - linePointsArray.get(i).getP1().y) < 5){ if(linePointsArray.get(j).getP1().y != linePointsArray.get(i).getP1().y){ closeLineYPos.add(linePointsArray.get(j).getP1().y); } } } } /*for (double num : closeLineYPos){ System.out.println(num); } */ //2. Now check if there are four of these are close to each other. //Go through all of the items in this list and check if four of them are close together //Check first four items, traverse down a step {0,1,2,3} -> {1,2,3,4} -> {2,3,4,5} //If 4 items are close together, //Then add them to a new array that holds Line Cluster Values. //Go down 4 positions down since, as do not want duplicates. //Now have an array of at least four lines that are close together. //Sort array and remove duplicates Collections.sort(closeLineYPos); closeLineYPos = removeDuplicates(closeLineYPos); //DISPLAYING AS EXCEPTED! WOO! for (double y : closeLineYPos){ System.out.println("CloseLineYPos: " + y); } if(closeLineYPos.size() >= 4) { //FOR every item in array of CloseLines for(int i= 0; i< closeLineYPos.size(); i++){ //If last comparator is at end of array. if(i + 4 >= closeLineYPos.size()){ break; } else{ //Add 4 values of CloseLine Array to a tempArray double[] tempArray = new double[4]; tempArray[0] = closeLineYPos.get(i); tempArray[1] = closeLineYPos.get(i + 1); tempArray[2] = closeLineYPos.get(i + 2); tempArray[3] = closeLineYPos.get(i + 3); //Check standard deviation between these 4 values. //If it SD is less than 5 then it is considered to be a cluster of lines. if(StandardDeviation(tempArray) < STANDARD_DEVIATION_THRESHOLD){ //System.out.println("tempArray PT: "+tempArray[0] + " , " + tempArray[1] + " , " + tempArray[2] + " , " + tempArray[3]); //System.out.println("tempArray SD: " + StandardDeviation(tempArray)); //Store array clusterArray.add(tempArray); //If I + 4 is less than the size of the array then increment by 4 //Go down +4 positions in closeLineYPos array if((i + 4 < closeLineYPos.size())){ //System.out.println("IF, i = " + i + " -> "+ (i+4) + ", CloseLineYpos size= " + closeLineYPos.size()); i = i+4; } else{ //break //System.out.println("ELSE, i = " + i+ " closeLineYpos size= " + closeLineYPos.size()); Thread.sleep(2000); break; } } } } } /* System.out.println("Cluster Coordinates: "); for(double[] items : clusterArray){ for(int i = 0; i = 1){ returnArray.add(true); returnArray.add(closeLineYPos.size()); returnArray.add(clusterCount); returnArray.add(clustersFoundRGB); } else{ returnArray.add(false); returnArray.add(closeLineYPos.size()); returnArray.add(clusterCount); } } } catch (Exception e) { System.err.println(e); } return returnArray; } private static ArrayList ClassifierLineClusterPt(ArrayList linePointsArray, Mat clustersFoundRGB){ /* ADDITION: This will check for a cluster of lines that are close together. 1. Go through the list of Y positions(start point) in parsed array. If, there is a small distance between them, then, add to closeLineArray. Have all Y positions that are close to each other now. Need to find the lines that are clustered together. Now check if there are four of these are close to each other. 2. Go through list of closeLine. Get first four lines, traversing down a step each iteration {0,1,2,3} -> {1,2,3,4} -> {2,3,4,5} If, those 4 lines are close together, Then, add them to a new array that holds Line Cluster Values. Go to line 4 positions down since, as do not want duplicates. 3. */ ArrayList returnArray = new ArrayList(); ArrayList closeLinePts = new ArrayList(); ArrayList clusterPtArray = new ArrayList(); int clusterCount = 0; try { if(linePointsArray.size()> 1) { /* //Display input array TESTING PURPOSES for (int i = 0; i < linePointsArray.size(); i++) { System.out.println(linePointsArray.get(i).toString()); } */ //1. Check if y points are close together //go thru list and compare values against each other for (int i = 0; i < linePointsArray.size(); i++){ //System.out.println("i: "+ linePointsArray.get(i).getP1().y); for (int j = 0; j < linePointsArray.size(); j++) { //System.out.println("j: "+ linePointsArray.get(j).getP1().y); //Check if difference is less than 4 and the values are not duplicates. if(Math.abs(linePointsArray.get(j).getP1().y - linePointsArray.get(i).getP1().y) < 5){ if(linePointsArray.get(j).getP1().y != linePointsArray.get(i).getP1().y){ closeLinePts.add(linePointsArray.get(i)); } } } } //2. Now check if there are four of these are close to each other. //Go through all of the items in this list and check if four of them are close together //Check first four items, traverse down a step {0,1,2,3} -> {1,2,3,4} -> {2,3,4,5} //If 4 items are close together, //Then add them to a new array that holds Line Cluster Values. //Go down 4 positions down since, as do not want duplicates. //Now have an array of at least four lines that are close together. //Sort array and remove duplicates Collections.sort(closeLinePts, new Comparator() { @Override public int compare(StartAndEndPoint p1, StartAndEndPoint p2) { return (int)(p1.getP1().y - p2.getP1().y); } }); closeLinePts = removeDuplicates(closeLinePts); //DISPLAYING AS EXCEPTED! WOO! /*for (StartAndEndPoint pt : closeLinePts) { System.out.println("CloseLinePTs: " + pt.getP1().y); }*/ if(closeLinePts.size() >= 4) { //FOR every item in array of CloseLines for(int i= 0; i < closeLinePts.size(); i++){ //If last comparator is at end of array. if(i + 4 >= closeLinePts.size()){ break; } else{ //Add 4 values of CloseLinePt Array to a tempArray StartAndEndPoint[] tempPtArray = new StartAndEndPoint[4]; tempPtArray[0] = closeLinePts.get(i); tempPtArray[1] = closeLinePts.get(i + 1); tempPtArray[2] = closeLinePts.get(i + 2); tempPtArray[3] = closeLinePts.get(i + 3); //Check standard deviation between these 4 values. //If it SD is less than 5 then it is considered to be a cluster of lines. if(ClusterCheck(tempPtArray)){ //System.out.println("tempArray PT: "+tempPtArray[0] + " , " + tempPtArray[1] + " , " + tempPtArray[2] + " , " + tempPtArray[3]); //Store array clusterPtArray.add(tempPtArray); //If I + 4 is less than the size of the array then increment by 4 //Go down +4 positions in closeLineYPos array if((i + 4 < closeLinePts.size())){ //System.out.println("IF, i = " + i + " -> "+ (i+4) + ", CloseLineYpos size= " + closeLineYPos.size()); i = i+4; } else{ //break Thread.sleep(2000); //System.out.println("End of closeLinePts -> break , i = " + i+ " closeLineYpos size= " + closeLinePts.size()); break; } } } } } /*System.out.println("Cluster Coordinates: "); for(StartAndEndPoint[] items : clusterPtArray){ for(int i = 0; i = 1){ returnArray.add(true); returnArray.add(clusterCount); returnArray.add(clustersFoundRGB); } else{ returnArray.add(false); returnArray.add(clusterCount); returnArray.add(clustersFoundRGB); } } } catch (Exception e) { System.err.println(e.getMessage()); } return returnArray; } //SUPER CLASSIFIER FUNCTIONS private static boolean LineCountOrCluster(int lineCount, ArrayList linePointsArray, Mat clustersFoundRGB){ ArrayList lineClusterResult = ClassifierLineClusterPt(linePointsArray, clustersFoundRGB); //String test = ClassifierLineClusterPt(linePointsArray, clustersFoundRGB).get(0).toString(); if(ClassifierLineCount(lineCount) == true){ System.out.println("LineCount classifier Successful: " + '\t' +"LinesFound: " + lineCount); return true; } else if(lineClusterResult.get(0).toString() == "true"){ System.out.println("LineCluster classifier Successful: " + '\t' + "LinesFound: " + lineCount + '\t' + "ClustersFound: " + lineClusterResult.get(1)); return false; } return false; } //MAIN public static void main(String[] args) { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); try { ArrayList pointArrayList = new ArrayList<>(); //Variables Mat edgesDetected = new Mat(); Mat edgesDetectedRGB = new Mat(); Mat clustersFoundRGB = new Mat(); String directory = "/Scratch/cpb16/is-sheet-music-encore/lowres-download-images/MU/"; //!!!!!!!!!!!!!!!!!!!!!!!!!!!NOT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //mdp.39015097852365-2.png 176 lines Contents page. //mdp.39015097852555-3.png 76 lines //!!!!!!!!!!!!!!!!!!!!!!!!!!!NOTNOT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //coo.31924062612282-9.png 8 lines //String default_file = directory+"NotSheetMusic/coo.31924062612282-9.png"; //String default_file = directory+"NotSheetMusic/mdp.39015097852365-2.png"; String default_file ="TestImages/NotNot/mdp.39015080972303-3.png"; //System.out.println(default_file); //String default_file = "TestImages/NotSheetMusic01.png"; //String default_file = "TestImages/NotSheetMusic02.png"; //String default_file = "TestImages/SheetMusic01.png"; //String default_file = "TestImages/SheetMusic02.png"; //String default_file = "TestImages/vLine.png"; String filename = ((args.length > 0) ? args[0] : default_file); File file = new File(filename); if(!file.exists()){System.err.println("Image not found: "+ filename);} int horizontalLineCount =0; // Load an image Mat original = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE); // Edge detection Imgproc.adaptiveThreshold(original, edgesDetected,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 15, 4); //Convert to RGB for future use Imgproc.cvtColor(edgesDetected, edgesDetectedRGB, Imgproc.COLOR_GRAY2BGR); clustersFoundRGB = edgesDetectedRGB.clone(); Mat linesP = new Mat(); // will hold the results of the detection //(edgeDetectedImage, outputOfDetection(r,θ), resolution of rho, resolution of theta, threshold (minimum num of intersections) double minLineLength = edgesDetectedRGB.size().width/8; Imgproc.HoughLinesP(edgesDetected, linesP, 1, Math.PI / 720, HOUGHLINEP_THRESHOLD, minLineLength,MAXLINEGAP); // runs the actual detection //System.out.println("Before Gradient Filtering num lines: " + linesP.rows()); // Draw the lines for (int x = 0; x < linesP.rows(); x++) { double[] l = linesP.get(x, 0); Point p1 = new Point(l[0], l[1]); Point p2 = new Point(l[2], l[3]); double m = Math.abs(p2.y - p1.y)/(p2.x - p1.x); if(m<=SLOPEGRADIENT) { Imgproc.line(edgesDetectedRGB, p1, p2, new Scalar(0, 0, 255), 1, Imgproc.LINE_4, 0); horizontalLineCount++; pointArrayList.add(new StartAndEndPoint(p1, p2)); } } //Point is a co ordinate (x, y) //Prove by finding number of points from one end to other: //Get width of image. //File filenameTest = new File("TestImages/NotSheetMusic02.png"); //BufferedImage i = ImageIO.read(filenameTest); BufferedImage toBeClassifiedImg = toBufferedImage(edgesDetectedRGB); //Display Results //HighGui.imshow("Source", original); //HighGui.imshow("Just Edges", justEdges); //TESTING HighGui.imshow("LINES FOUND", edgesDetectedRGB); HighGui.imshow("CLUSTERS FOUND", clustersFoundRGB); //HighGui.imshow("Detected Lines (in red) - negative", edgesDetectedRGBProb); //System.out.println("LINE COUNT RESULT: " + ClassifierLineCount(horizontalLineCount) + '\t' +"LinesFound: " + horizontalLineCount); //COUNT OF LINES CLASSIFICATION //System.out.println("LINE CLUSTER RESULT: " + ClassifierLineClusterOLD(toBeClassifiedImg).get(0) + '\t' + "LinesFound: " + ClassifierLineClusterOLD(toBeClassifiedImg).get(1) + '\t' + "ClustersFound: " + ClassifierLineClusterOLD(toBeClassifiedImg).get(2)); //System.out.println("NEW CLUSTER RESULTS: " + ClassifierLineClusterPt(pointArrayList,clustersFoundRGB).get(0) + '\t' + "LinesFound: " + horizontalLineCount + '\t' + "ClustersFound: " + ClassifierLineClusterPt(pointArrayList,clustersFoundRGB).get(1)); //System.out.println(ClassifierLineClusterPt(pointArrayList, clustersFoundRGB)); System.out.println("TEST: " + LineCountOrCluster(horizontalLineCount, pointArrayList, clustersFoundRGB)); // Wait and Exit HighGui.waitKey(); System.exit(0); } catch(Exception e){ System.err.println(e); } } }