From 673f005fe6412776d5e6a17b10d4b8fdf84ac50e Mon Sep 17 00:00:00 2001 From: Anthony Stirling <77850077+Frooodle@users.noreply.github.com> Date: Sat, 17 Feb 2024 23:23:07 +0000 Subject: [PATCH] Game fixes and ocr docs (#824) --- .../docker-compose-latest-lite-security.yml | 2 +- .../docker-compose-latest-security.yml | 2 +- ...ker-compose-latest-ultra-lite-security.yml | 2 +- exampleYmlFiles/docker-compose-latest.yml | 2 +- scripts/detect-blank-pages.py | 37 ------------------- .../SPDF/config/EndpointConfiguration.java | 4 +- .../controller/api/misc/OCRController.java | 2 +- .../controller/web/OtherWebController.java | 2 +- src/main/resources/static/css/game.css | 2 +- src/main/resources/static/js/downloader.js | 14 +++++++ .../resources/templates/fragments/common.html | 26 ++++++++++++- .../templates/misc/extract-image-scans.html | 1 + .../templates/misc/extract-images.html | 1 + 13 files changed, 50 insertions(+), 47 deletions(-) delete mode 100644 scripts/detect-blank-pages.py diff --git a/exampleYmlFiles/docker-compose-latest-lite-security.yml b/exampleYmlFiles/docker-compose-latest-lite-security.yml index 90e4c5bf..2db1b416 100644 --- a/exampleYmlFiles/docker-compose-latest-lite-security.yml +++ b/exampleYmlFiles/docker-compose-latest-lite-security.yml @@ -15,7 +15,7 @@ services: ports: - 8080:8080 volumes: - - /stirling/latest/data:/usr/share/tesseract-ocr/5/tessdata:rw + - /stirling/latest/data:/usr/share/tessdata:rw - /stirling/latest/config:/configs:rw - /stirling/latest/logs:/logs:rw environment: diff --git a/exampleYmlFiles/docker-compose-latest-security.yml b/exampleYmlFiles/docker-compose-latest-security.yml index 513bb582..830c425f 100644 --- a/exampleYmlFiles/docker-compose-latest-security.yml +++ b/exampleYmlFiles/docker-compose-latest-security.yml @@ -15,7 +15,7 @@ services: ports: - 8080:8080 volumes: - - /stirling/latest/data:/usr/share/tesseract-ocr/5/tessdata:rw + - /stirling/latest/data:/usr/share/tessdata:rw - /stirling/latest/config:/configs:rw - /stirling/latest/logs:/logs:rw environment: diff --git a/exampleYmlFiles/docker-compose-latest-ultra-lite-security.yml b/exampleYmlFiles/docker-compose-latest-ultra-lite-security.yml index b7848696..c0dd09ce 100644 --- a/exampleYmlFiles/docker-compose-latest-ultra-lite-security.yml +++ b/exampleYmlFiles/docker-compose-latest-ultra-lite-security.yml @@ -15,7 +15,7 @@ services: ports: - 8080:8080 volumes: - - /stirling/latest/data:/usr/share/tesseract-ocr/5/tessdata:rw + - /stirling/latest/data:/usr/share/tessdata:rw - /stirling/latest/config:/configs:rw - /stirling/latest/logs:/logs:rw environment: diff --git a/exampleYmlFiles/docker-compose-latest.yml b/exampleYmlFiles/docker-compose-latest.yml index d506e424..e39087dd 100644 --- a/exampleYmlFiles/docker-compose-latest.yml +++ b/exampleYmlFiles/docker-compose-latest.yml @@ -15,7 +15,7 @@ services: ports: - 8080:8080 volumes: - - /stirling/latest/data:/usr/share/tesseract-ocr/5/tessdata:rw + - /stirling/latest/data:/usr/share/tessdata:rw - /stirling/latest/config:/configs:rw - /stirling/latest/logs:/logs:rw environment: diff --git a/scripts/detect-blank-pages.py b/scripts/detect-blank-pages.py deleted file mode 100644 index 4ca724c2..00000000 --- a/scripts/detect-blank-pages.py +++ /dev/null @@ -1,37 +0,0 @@ -import cv2 -import sys -import argparse -import numpy as np - -def is_blank_image(image_path, threshold=10, white_percent=99, white_value=255, blur_size=5): - image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE) - - if image is None: - print(f"Error: Unable to read the image file: {image_path}") - return False - - # Apply Gaussian blur to reduce noise - blurred_image = cv2.GaussianBlur(image, (blur_size, blur_size), 0) - - _, thresholded_image = cv2.threshold(blurred_image, white_value - threshold, white_value, cv2.THRESH_BINARY) - - # Calculate the percentage of white pixels in the thresholded image - white_pixels = np.sum(thresholded_image == white_value) - white_pixel_percentage = (white_pixels / thresholded_image.size) * 100 - - print(f"Page has white pixel percent of {white_pixel_percentage}") - return white_pixel_percentage >= white_percent - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description='Detect if an image is considered blank or not.') - parser.add_argument('image_path', help='The path to the image file.') - parser.add_argument('-t', '--threshold', type=int, default=10, help='Threshold for determining white pixels. The default value is 10.') - parser.add_argument('-w', '--white_percent', type=float, default=99, help='The percentage of white pixels for an image to be considered blank. The default value is 99.') - args = parser.parse_args() - - blank = is_blank_image(args.image_path, args.threshold, args.white_percent) - - # Return code 1: The image is considered blank. - # Return code 0: The image is not considered blank. - sys.exit(int(blank)) diff --git a/src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java b/src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java index f82c189f..752474a0 100644 --- a/src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java +++ b/src/main/java/stirling/software/SPDF/config/EndpointConfiguration.java @@ -140,7 +140,6 @@ public class EndpointConfiguration { // CLI addEndpointToGroup("CLI", "compress-pdf"); addEndpointToGroup("CLI", "extract-image-scans"); - addEndpointToGroup("CLI", "remove-blanks"); addEndpointToGroup("CLI", "repair"); addEndpointToGroup("CLI", "pdf-to-pdfa"); addEndpointToGroup("CLI", "file-to-pdf"); @@ -218,7 +217,8 @@ public class EndpointConfiguration { addEndpointToGroup("Java", "split-by-size-or-count"); addEndpointToGroup("Java", "overlay-pdf"); addEndpointToGroup("Java", "split-pdf-by-sections"); - + addEndpointToGroup("Java", "remove-blanks"); + // Javascript addEndpointToGroup("Javascript", "pdf-organizer"); addEndpointToGroup("Javascript", "sign"); diff --git a/src/main/java/stirling/software/SPDF/controller/api/misc/OCRController.java b/src/main/java/stirling/software/SPDF/controller/api/misc/OCRController.java index 542e3c6d..07947587 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/misc/OCRController.java +++ b/src/main/java/stirling/software/SPDF/controller/api/misc/OCRController.java @@ -41,7 +41,7 @@ public class OCRController { private static final Logger logger = LoggerFactory.getLogger(OCRController.class); public List getAvailableTesseractLanguages() { - String tessdataDir = "/usr/share/tesseract-ocr/5/tessdata"; + String tessdataDir = "/usr/share/tessdata"; File[] files = new File(tessdataDir).listFiles(); if (files == null) { return Collections.emptyList(); diff --git a/src/main/java/stirling/software/SPDF/controller/web/OtherWebController.java b/src/main/java/stirling/software/SPDF/controller/web/OtherWebController.java index a7c10908..b93a89e4 100644 --- a/src/main/java/stirling/software/SPDF/controller/web/OtherWebController.java +++ b/src/main/java/stirling/software/SPDF/controller/web/OtherWebController.java @@ -82,7 +82,7 @@ public class OtherWebController { } public List getAvailableTesseractLanguages() { - String tessdataDir = "/usr/share/tesseract-ocr/5/tessdata"; + String tessdataDir = "/usr/share/tessdata"; File[] files = new File(tessdataDir).listFiles(); if (files == null) { return Collections.emptyList(); diff --git a/src/main/resources/static/css/game.css b/src/main/resources/static/css/game.css index 5b9f27d2..fc2f7262 100644 --- a/src/main/resources/static/css/game.css +++ b/src/main/resources/static/css/game.css @@ -42,7 +42,7 @@ } #lives { top: 10px; - left: calc(7vw); /* Adjusted position */ + left: calc(9vw); /* Adjusted position */ } #high-score { top: 10px; diff --git a/src/main/resources/static/js/downloader.js b/src/main/resources/static/js/downloader.js index 842e9df0..a4794e12 100644 --- a/src/main/resources/static/js/downloader.js +++ b/src/main/resources/static/js/downloader.js @@ -25,6 +25,17 @@ $(document).ready(function () { const originalButtonText = $("#submitBtn").text(); $("#submitBtn").text("Processing..."); console.log(override); + + // Set a timeout to show the game button if operation takes more than 5 seconds + const timeoutId = setTimeout(() => { + var boredWaiting = localStorage.getItem("boredWaiting") || "disabled"; + const showGameBtn = document.getElementById('show-game-btn'); + if(boredWaiting === "enabled" && showGameBtn){ + showGameBtn.style.display = 'block'; + } + }, 5000); + + try { if (remoteCall === true) { if (override === "multi" || (!multiple && files.length > 1 && override !== "single")) { @@ -33,8 +44,11 @@ $(document).ready(function () { await handleSingleDownload(url, formData); } } + clearTimeout(timeoutId); $("#submitBtn").text(originalButtonText); + } catch (error) { + clearTimeout(timeoutId); handleDownloadError(error); $("#submitBtn").text(originalButtonText); console.error(error); diff --git a/src/main/resources/templates/fragments/common.html b/src/main/resources/templates/fragments/common.html index 78f229c6..10c38afa 100644 --- a/src/main/resources/templates/fragments/common.html +++ b/src/main/resources/templates/fragments/common.html @@ -70,6 +70,24 @@
@@ -115,6 +135,7 @@
+ @@ -139,6 +160,9 @@ - + + + + \ No newline at end of file diff --git a/src/main/resources/templates/misc/extract-image-scans.html b/src/main/resources/templates/misc/extract-image-scans.html index 57abe8ef..a673f4a3 100644 --- a/src/main/resources/templates/misc/extract-image-scans.html +++ b/src/main/resources/templates/misc/extract-image-scans.html @@ -5,6 +5,7 @@ +
diff --git a/src/main/resources/templates/misc/extract-images.html b/src/main/resources/templates/misc/extract-images.html index 22977ed1..b14c9b20 100644 --- a/src/main/resources/templates/misc/extract-images.html +++ b/src/main/resources/templates/misc/extract-images.html @@ -5,6 +5,7 @@ +