Changeset 33449 for other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaClassifierComparison.java
- Timestamp:
- 2019-09-02T17:08:03+12:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaClassifierComparison.java
r33447 r33449 182 182 //Execute classifierType defined from arguement 183 183 184 File imgCheck = new File(imageFilename); 185 if(!imgCheck.exists()){System.err.println("Image not found: "+ imageFilename);} 186 184 187 //Split output by tab for processing in next java program 185 188 //imageFilename = 1, result = 3, classifierType = 4 … … 201 204 break; 202 205 case "morphology": 203 algorithmResult = Algorithm_Morphology OLD(imageFilename);206 algorithmResult = Algorithm_Morphology(imageFilename); 204 207 bw.write("Filename:" + '\t' + imageFilename + '\t' + "Classified as:" + '\t' + algorithmResult.getBoolean() + '\t' + "Number of areas:" + '\t' + algorithmResult.getInteger() + '\t' + classifierType + '\n'); 205 208 break; … … 330 333 Boolean isSheetMusic = null; 331 334 Pair returnVariables = new Pair(); 335 int areaCounter = 0; 332 336 try{ 333 //Variables334 int areaCounter = 0;335 337 Mat edgesDetectedRGB = new Mat(); 336 338 Mat original = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE); 339 340 System.out.println("Width: " + original.width() + " Height: " + original.height()); 337 341 338 342 ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>(); … … 361 365 for (int i = 0; i < contours.size(); i++) { 362 366 double area = Imgproc.contourArea(contours.get(i)); 367 System.out.println("AREA: " + area); 363 368 //Check if area detected meets threshold 364 369 if(area > THRESHOLD_AREA_SIZE) { 365 370 areaCounter++; 366 //System.out.println("AREA: " + area); 367 } 368 } 369 370 371 372 373 371 372 } 373 } 374 System.out.println("areacount = " + areaCounter); 374 375 375 376 //Calculates if sheet music or not 376 377 if(areaCounter >= THRESHOLD_AREA_COUNT){ 377 returnVariables.setBoolean(true); 378 isSheetMusic = true; 379 returnVariables.setBoolean(isSheetMusic); 378 380 returnVariables.setInteger(areaCounter); 379 381 } … … 389 391 Boolean isSheetMusic = null; 390 392 Pair returnVariables = new Pair(); 393 int FILLED = -1; 391 394 try{ 392 int FILLED = -1;393 //Display Original394 //imageViewer("original", original1);395 Mat original = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE);395 Mat original1 = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE); 396 System.out.println("Width: " + original1.width() + " Height: " + original1.height()); 397 Mat original = original1.clone(); 398 Imgproc.adaptiveThreshold(original1, original,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 15, THRESHOLD_C); 396 399 Mat test = original.clone(); 397 //imageViewer("00 Inverse Binarized Original", test);398 399 400 400 //************************************ 401 401 //Large Object Removal … … 408 408 Mat denoize = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5)); 409 409 Imgproc.morphologyEx(srcLOR,maskLOR, Imgproc.MORPH_OPEN, denoize); 410 //imageViewer("01 Denoize - mask", maskLOR);411 410 412 411 //close up gaps 413 412 Mat gapCloser = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5)); 414 413 Imgproc.morphologyEx(maskLOR,maskLOR,Imgproc.MORPH_CLOSE, gapCloser); 415 //imageViewer("02 gap closer - mask", maskLOR);416 414 417 415 //Isolate large items 418 416 Mat isolateLarge = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(8, 8)); 419 417 Imgproc.morphologyEx(maskLOR,maskLOR,Imgproc.MORPH_OPEN, isolateLarge); 420 //imageViewer("03 Isolate Large - mask", maskLOR);421 418 422 419 //Remove large items from image 423 420 Core.bitwise_not(maskLOR,maskLOR); 424 421 srcLOR.copyTo(dstLOR, maskLOR); 425 //imageViewer("04 Large Items Removed", dstLOR);426 422 427 423 //**************************************** … … 435 431 Mat startSOR =Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(7,7)); 436 432 Imgproc.morphologyEx(srcSOR,maskSOR, Imgproc.MORPH_OPEN, startSOR); 437 //imageViewer("11 show small - mask", maskSOR);438 433 439 434 Mat highlightSmall = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(7,7)); 440 435 Imgproc.dilate(maskSOR, maskSOR, highlightSmall); 441 //imageViewer("12 highlight small - mask", maskSOR); 436 442 437 443 438 /* Mat isolateSmall =Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,10)); … … 449 444 Core.bitwise_not(maskSOR, maskSOR); 450 445 srcSOR.copyTo(dstSOR, maskSOR); 451 //imageViewer("14 Small Items Removed", dstSOR);452 446 453 447 … … 458 452 Mat kernelErode = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(15,2)); //10,2 459 453 Imgproc.erode(dstSOR,test,kernelErode); 460 //imageViewer("21 Erode plus pre", test); 454 461 455 462 456 Mat kernelDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //20,3 463 457 Imgproc.dilate(test,test,kernelDilate); 464 //imageViewer("22 Dilate", test); 458 465 459 466 460 Mat kernelClose = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //4,4 467 461 Imgproc.morphologyEx(test, test, Imgproc.MORPH_CLOSE, kernelClose); 468 //imageViewer("23 Close", test); 462 469 463 470 464 471 465 Mat kernelErode02 = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //10,1 472 466 Imgproc.erode(test,test,kernelErode02); 473 //imageViewer("24 Erode (Final)", test); 467 474 468 475 469 //******************************************************************************** … … 511 505 } 512 506 } 513 //imageViewer("80 All Contours found", allContoursFound);514 //imageViewer("81 Large Contours Found", largeContoursFound);515 507 516 508 //***************************************************************** … … 536 528 Imgproc.circle(circleOutput, centers[i], (int) radius[i][0],new Scalar(255, 0, 0), 1); 537 529 } 538 //imageViewer("82 Circles found", circleOutput); 530 539 531 540 532 //******************************************************************************** … … 551 543 Imgproc.circle(centreOutput, new Point(x, y), 4, new Scalar(255, 255, 255), 30); 552 544 } 553 //imageViewer("83 Centres found", centreOutput);554 555 545 556 546 //*********************************************** … … 563 553 Mat postDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(150,15)); 564 554 Imgproc.dilate(centreOutput,centreOutput,postDilate); 565 //imageViewer("91 PostDilated", centreOutput);566 555 567 556 Mat postClose = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //4,4 568 557 Imgproc.morphologyEx(centreOutput, centreOutput, Imgproc.MORPH_CLOSE, postClose); 569 //imageViewer("92 PostClose", centreOutput);570 558 571 559 Mat postDenoize = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(100,100)); 572 560 Imgproc.morphologyEx(centreOutput,centreOutput, Imgproc.MORPH_OPEN, postDenoize); 573 //imageViewer("93 PostDenoize", centreOutput);574 575 //Mat postOutline = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(50,50));576 //Imgproc.morphologyEx(centreOutput, centreOutput, Imgproc.MORPH_GRADIENT, postOutline);577 561 578 562 //Find area … … 584 568 double area = Imgproc.contourArea(postContours.get(i)); 585 569 if(area > THRESHOLD_AREA_SIZE) { 586 System.out.println("POST AREA: " + area + "AREA COUNTER: " + areaCounter);587 //Imgproc.drawContours(postContoursFound, postContours, i, new Scalar(0, 255, 0), FILLED);570 //System.err.println("POST AREA: " + area); 571 Imgproc.drawContours(postContoursFound, postContours, i, new Scalar(0, 255, 0), FILLED); 588 572 areaCounter++; 589 573 } 590 574 } 591 592 //imageViewer("93 PostEND", postContoursFound); 593 594 //Calculates if sheet music or not 575 //Classifier Calculation 595 576 if(areaCounter >= THRESHOLD_AREA_COUNT){ 596 returnVariables = new Pair(true, areaCounter); 597 //returnVariables.setBoolean(true); 598 //returnVariables.setInteger(areaCounter); 599 System.out.println("TEST RETURN VARIABLES: "+ returnVariables.toString()); 600 } 601 577 returnVariables.setBoolean(true); 578 returnVariables.setInteger(areaCounter); 579 } 602 580 } 603 581 catch(Exception e){
Note:
See TracChangeset
for help on using the changeset viewer.